Audio Filter with pulse function

3 views (last 30 days)
Gage Haas
Gage Haas on 1 Aug 2017
Edited: Gage Haas on 1 Aug 2017
I am trying to take a .wav file, read it using wavread and add a sine wave of 12khz to the file to create a noisy signal. I am then trying to create a pulse that when multiplied with the frequency components of the noisy signal will zero out unwanted frequencies. In this example i am trying to make a filter with a cutoff frequency of 10000 Hz so I am assigning ones in the range of -10000 to 10000 hz and assigning zeros for the rest of the length of the signal. However, when I multiply the filter and the noisy signal it doesnt produce the correct results. My code is below, I was wondering where I went wrong.
[y,fs]=wavread('one.wav'); % fs=44101
f=12000;
fnyquist=fs/2
L=length(y)
nfft=1024;
ts=1/fs;
%t=0:ts:(L-1)/fs; %lengthy /fs = duration of audiofile
t = (0:L-1)/fs;
x=sin(2*pi*f*t);
%sound(x,fs)
figure('Name','Time Domain Audio','NumberTitle','off');
plot(t,y)
left = y(:,1); %y was 1654400x2 and now is 1654400x1
wavwrite(x,fs,'sound.wav');
a=wavread('sound.wav');
Z=left+a;
%sound(Z,fs);
Y = fftshift(fft(Z));
f = (-(L-1)/2:L/2)/fs;
w = 2*pi*f;
MagY = abs(Y);
PhY = angle(Y)*180/pi;
figure('Name','freq ');
plot(f,MagY)
figure('Name','freq domain');
plot(w,MagY/L)
idx_p = find(f <= 10000,1);
idx_n = find(f >= -10000, 1);
lpf = zeros(1,L);
lpf (idx_n:idx_p) = 1;
figure('Name','lpf');
plot(f,lpf)
lpf2= lpf.'; %transposed from 1x1654400 to 1654400x1
filteredsignal=lpf2.*Y;
filteredsignal2=ifft(filteredsignal);
sound(filteredsignal2,fs);

Answers (0)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!