Hi,
I am trying to remove certain frequencies from a swept-sine signal by using a fourier transform, zeroing certain elements of the array, and then inverse transforming them. As far as I can tell I am doing it right, but obviously I am not because when I run the final comparison analysis the frequencies that aren't supposed to be there still exist.
clear all, clc, close allT=5; %time
A=1; %amplitude
F1=20; %startfrequency
F2=20000; %endfrequency
P0=0; %initialphase
FS=44100; %samplerate
B=16; %bitrate
R=(F2-F1)/T; %sweeprate
t=0:1/FS:T; %timevector
p=P0+2*pi*(F1+(R.*t)./2).*t; %phasevector
% Linear sine sweep
y=A*sin(p);L=size(y);figure(1)plot(t,y)%sound(y,FS,B);
%%Analysis fft
NFFT = 2^nextpow2(L(2)); % Next power of 2 from length of y
yfa = fft(y,NFFT)/L(2);f = FS/2*linspace(0,1,NFFT/2+1);figure(2)plot(f,2*abs(yfa(1:NFFT/2+1)))title('Single-Sided Amplitude Spectrum of y(t)')xlabel('Frequency (Hz)')ylabel('|Y(f)|')%%Inverse Transform
yf=fft(y); % Pure fft
yf(1:50000)=0; % bin removal
z=real(ifft(yf)); % ifft
figure(3)plot(t,z)%%New Analysis fft (for comparison)
NFFT = 2^nextpow2(L(2)); % Next power of 2 from length of yzfa = fft(z,NFFT)/L(2);f = FS/2*linspace(0,1,NFFT/2+1);figure(4)plot(f,2*abs(zfa(1:NFFT/2+1)))title('Single-Sided Amplitude Spectrum of y(t)')xlabel('Frequency (Hz)')ylabel('|Y(f)|')pause(5)%sound(z,FS,B)
The bit that seems to be causing me trouble is the %bin removal bit. Any ideas?
Thanks a lot
EDIT
Ok, so I figured out what was wrong with this part – it wasn't the bin removal section it was the ifft section. It shouldn't have included the excluded the imaginary parts:
%%Inverse Transformyf=fft(y); % Pure fftyf(1:50000)=0; % bin removalz=(ifft(yf)); % ifft
Now, my problem is that when I get the time domain plot of this: plot(t,real(z)) The frequencies that I deleted still exist, just at about half the amplitude. I would normally expect them to just disappear, should I?
Best Answer