FFT question (signal processing)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 all
T=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 y
zfa = 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 Transform
yf=fft(y); % Pure fft
yf(1:50000)=0; % bin removal
z=(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?
0 Kommentare
Akzeptierte Antwort
Wayne King
am 3 Dez. 2013
Bearbeitet: Wayne King
am 3 Dez. 2013
You can't just remove the "positive" frequencies in the DFT. If you have a real-valued signal, you get energy at two complex exponentials, the positive and negative frequencies. You have to remove both.
Example:
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+sin(2*pi*200*t);
xdft = fft(x);
% zero out 100-Hz occurs at bin 101 and 901
xdft([101 901]) = 0;
xhat = ifft(xdft);
plot(t(1:200),x(1:200),'k',t(1:200),xhat(1:200),'r')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!