I have a signal in Matlab defined by signal and t. As it is a noisy signal, I want to delete every component below a certain given frequency "x" Hz with the FFT. How could I do it? I guess the procedure is FFT the signal, delete those components and then apply the IFFT, but I don't know how to implement it. Any help is appreciated!
Asked
Active
Viewed 1.2k times
2
euskadi
- 23
- 1
- 1
- 3
1 Answers
1
In fact, deleting a certain frequency range from the FFT equals settings these frequency components to zero. Hence, you end up with the following code:
N = 1000;
signal = randn(N, 1);
N_clear = 490;
% Remove the calls to fftshift, if you want to delete the lower frequency components
S = fftshift(fft(signal));
S_cleared = S;
S_cleared(1:N_clear) = 0;
S_cleared(end-N_clear+2:end) = 0;
S_cleared = fftshift(S_cleared);
signal_cleared = ifft(S_cleared);
subplot(2,2,1);
plot(signal);
title('input signal');
subplot(2,2,2);
plot(abs(S));
title('input spectrum');
subplot(2,2,3);
plot(abs(S_cleared));
title('output spectrum');
subplot(2,2,4);
plot(signal_cleared);
title('output signal');
As you can see, the input signal is very quickly varying. Then, after filtering out almost all higher frequency parts, you end up with a smooth signal.
Note, that normally you use FIR/IIR lowpass/highpass filters for realtime-signal processing, because the FFT is block-based and cannot produce nice transitions between the processed blocks.
Maximilian Matthé
- 6,218
- 2
- 12
- 19

N_clear? If I want to delete frequency components below 1Hz, knowing that f=k*fs/N, with a given sampling frequency, N the length of the signal and k a vector of the length of the signal, I should delete every component k that is under 1Hz from the S vector? Thanks for the answer! @maximilian-matthé – euskadi Nov 09 '16 at 15:27