Question

My problem is to obtain original signal from amplitude spectrum (fft) based on inverse fft but only for some frequency range ex. 8-12 Hz. Could anyone help me? I try to used:

xdft=fft(x); 
ixdft=ifft(xdft(a:b)), %where xdft(a:b) is |Y(f)| for freq 8-12 Hz.

But it doesn't want to work.

Was it helpful?

Solution

You can set all the values of xdft to zero except those you want, i.e.,

xdft = fft(x);
xdft = xdft(1:ceil(length(xdft) / 2));
xdft(1:a) = 0;
xdft(b+1:end) = 0;
ixdft = ifft(xdft, 'symmetric');

The reason I have taken only half of the original FFT'd data is that your result will be symmetric about Fs / 2 (where Fs is the sample rate), and if you don't do the same thing to the frequencies either side of the centre, you will get a complex signal out. Instead of doing the same thing to both sides manually, I've just taken one side, modified it, and told ifft that it has to reconstruct the data for the full frequency range by appending a mirror image of what you pass it; this by done by calling it with the 'symmetric' option.

If you need to figure out what a and b should be for some frequency, you can first create a vector of the frequencies at which you've performed the FFT, then find those frequencies that are within your range, like so:

xdft = fft(x);
xdft = xdft(1:ceil(length(xdft) / 2));
f = linspace(0, Fs / 2, length(xdft));
keepInd = f >= 8 & f <= 12; % Keep frequencies between 8 and 12 Hz
xdft(~keepInd) = 0;

Note that I've actually omitted the use of the two variables a and b altogether in this example and opted for logical indexing, and that Fs is the sample rate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top