FFT question (signal processing)

2 ビュー (過去 30 日間)
Theo
Theo 2013 年 12 月 3 日
コメント済み: Theo 2013 年 12 月 3 日
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?

採用された回答

Wayne King
Wayne King 2013 年 12 月 3 日
編集済み: Wayne King 2013 年 12 月 3 日
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')
  1 件のコメント
Theo
Theo 2013 年 12 月 3 日
Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by