Search code examples
matlabplotsignal-processingfftlowpass-filter

Why is my resultant signal not appearing correctly? MATLAB


I have written some code below in MATLAB to filter a Noisy signal (noise_f is the noisy signal, where it is a 1 x 256 vector):

s_nf = size(noise_f);
size_f = s_nf(2); 

lp_tresh = ceil((2/3)*size_f);  
lp_f = zeros(1,256); 
for n = 1:lp_tresh
    lp_f(n) = noise_f(n); 
end
subplot(4,3,7);
plot(abs(lp_f)); title('LowPass Filter Result');

Here is a time domain image of the noisy signal:

enter image description here

Here is a time domain analysis of this signal:

enter image description here

Once I plot the result of the lowpass filter, I get this:

enter image description here

Now I apply the ifft on the 1 x 256 vector that represents the filtered signal and for some reason, I get this image :

enter image description here

Can someone explain to me how to get the proper plot of the filtered signal? All help and suggestions will be appreciated!


Solution

  • To get a strictly real result, the input to an IFFT must be complex conjugate symmetric. Chopping off the part of the FFT above bin N/2 (or below bin 0) destroys that symmetry if any of those bins are non-zero.

    Thus, a low-pass filter will only work in the frequency domain if it's cutoff is below bin N/2 (representing Fs/2). Then make sure the filtered result is conjugate symmetric before doing the IFFT.