HydrogenAudio

Hydrogenaudio Forum => Scientific Discussion => Topic started by: mikrophun on 2011-11-10 10:29:11

Title: fft filtering code
Post by: mikrophun on 2011-11-10 10:29:11
hi all,
is there anyone can help me to read the code below:
(i really don't understand about matlab programming)

clear all;
clc;

[a,fs] = wavread('msrnbng2.wav');
x1 = length(a)
sr = a(1:2500000);
x1 = length(sr)

dw = 8192;
skala = fs/dw;

%saron1
mi1 = int16(500/skala);
ma1 = int16(540/skala);
%saron2
mi2 = int16(688/skala);
ma2 = int16(720/skala);
%saron3
mi3 = int16(780/skala);
ma3 = int16(830/skala);
%saron5
mi5 = int16(890/skala);
ma5 = int16(920/skala);
%saron6
mi6 = int16(950/skala);
ma6 = int16(970/skala);
%saron1'
mi1t = int16(1008/skala);
ma1t = int16(1078/skala);

beng=[]    %menyimpan matrix2, variable matrix digunakan untuk menampilkan hasil 3D
aw=1        %dimulai dari 1. digunakan untuk perulangan.
dd1=400;    %panjang sinyal yang mau diambil

while aw<= (length(sr)-dw)  %while aw <=(2500000-8192)     
    ass = sr(aw:dw+aw);    %ass = sr (aw:8192+aw)   
    ff1 = fft(ass);        %b = fft(a(5000:10000),pnj);
    beng=[beng (abs(ff1(1:dd1)))];
    aw = aw + dw;          %aw = aw + 8192;
end

figure(1)
mesh(beng)      %menampilkan gambar 3D
xlabel('Times');
ylabel('Frekuensi');
zlabel('Amplitudo');
title('Perkiraan nada dalam bentuk 3D');

gambar1 = max(beng(mi1:ma1,:));
gambar2 = max(beng(mi2:ma2,:));
gambar3 = max(beng(mi3:ma3,:));
gambar5 = max(beng(mi5:ma5,:));
gambar6 = max(beng(mi6:ma6,:));
gambar7 = max(beng(mi1t:ma1t,:));
gambars = [gambar1;gambar2;gambar3;gambar5;gambar6;gambar7];
tampil = gambars';              %tampil = transpose dari gambars
pjg_tampil = length(tampil)    %ukuran panjang tampil

figure(2);
plot (tampil);
xlabel('Times');
ylabel('Frekuensi');
legend('Saron 1','Saron 2','Saron 3','Saron 5','Saron 6','Saron 1t');
%axis([0,620,0,350]);
title('Perkiraan nada dalam bentuk 2D');

figure(3);
%plot (tampil);
%xlabel('Times');
%ylabel('Frekuensi');
%legend('Saron 1','Saron 2','Saron 3','Saron 5','Saron 6','Saron 1t');
%axis([200,400,0,350]);
%title('Perkiraan nada dalam bentuk 2D from times 200-400');

%figure(4);
%plot (sr), title('waveform of msrnbng2');
subplot(2,1,1), plot (a), title('waveform of msrnbng2');
subplot(2,1,2), plot (sr), title('waveform of msrnbng2 from 1 to 2500000');
Title: fft filtering code
Post by: ojdo on 2011-11-10 13:00:28
Please try to be more specific about what you don't understand. Which lines, which constructs don't you understand? Fire up Matlab and execute the script line by line, always inspecting the contents of your workspace to understand what happens. If you arrive at a line you struggle to understand, ask specifically about that line.

P.S. Please use a [ codebox ] next time when you paste lengthy code.
Title: fft filtering code
Post by: mikrophun on 2011-11-11 00:49:08
thx for your suggestion ojdo. I'm new in this forum, so i still didn't understand the features that used to write. i'm sorry for not using codebox.
actually, I already run that program and done it. for several line on that code i still understand. but start from "beng[]" until "end" i'm having difficulty to figure out.

later, there's a new problem that i need to resolve.
1. how to make overlap with the windows length 8192 (it written in this line code "dw = 8192;"), hop size 25% from the first 2500000 signal.

2. do threshold 20% from each tone (pitch) to remove the noise. the tone that have value smaller than the threshold value, make it to be zero.

how do i solved the both problems? which line code do i need to change?
that makes me really confused.
i already googling to find the solution, but still i can't find the way how to modified the code.

thx before.