extract a thin band of frequencies from entire spectrum using FFT
Show older comments
Hello,
I have following program:
fs=1e4;
x=randn(1,1e4); %gaussian dist random signal
x_fft=fft(x); %fft of the signal
N=length(x);
omega=fs*[(0:N/2) (-N/2+1:-1)]/N; %frequency axis(bins)
figure;
plot(omega(1:N/2),2*abs(x_fft(1:N/2))); %plot of one-sided spectrum
Now I want to extract only a thin band of frequencies(say 500-520Hz) from the spectrum,take its ifft store the obtained time-domain signal in a variable y. I know it is bandpass filtering in TD and there is function fdesign.bandpass() in matlab aswell for this purpose, but I want to do it in frequency domain (using FFT and IFFT) as in my case, the samples are very large and BPF is very time consuming.
At the end, I want to have a small function, where I only enter the frequency band of interest as my input and I get the corresponding TD signal extracted as my output.
Please help.
Accepted Answer
More Answers (1)
Wayne King
on 16 Sep 2012
Edited: Wayne King
on 16 Sep 2012
You can just create a vector of zeros to match the size of the original DFT vector and then fill the correct indices of the vectors with the DFT coefficients. Remember for a real-valued signal, you will have to fill the appropriate negative and positive frequencies with the complex conjugates. Here I'll just give a simple example to pull out the 100-Hz component. For a band of frequencies, you'll need the vector for the band.
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+cos(2*pi*200*t);
xdft = fft(x);
% the DFT bins for 100 Hz are 101 and 1000-101+2
indices100 = [101 length(xdft)-101+2];
ydft = zeros(size(xdft));
ydft(indices100) = xdft(indices100);
y = ifft(ydft,'symmetric');
Categories
Find more on Fourier Analysis and Filtering 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!