0

I am trying to write a code in Matlab which takes a one or sum of sinosudal waves imposed with noise and try to filter it using the following algo :

  • first i take the input and place it in a vector

  • then i apply fft() to that vector and abs() to that fft
    - example if 'x' is the vector in which wave is stored then
    - y= abs(fft(x))

  • now in 'y' i make all the elements less than a certain threshold value 0

  • then apply the ifft() function to get the filtered signal lets say 'x1'

but the final wave i get even though a sinusoidal wave it is out phase (see the graph).is it because iam applying abs() to the fft??
But the material which i got this algo from doesn't discuss about this.
Do i need to apply any other filter so that i get the actual wave??

here is the plot of the two waves: one i got from above procedure and the other the actual wave which is a sine wave with no noise: my graph

see how my filtered wave and the actual wave are out of phase how to correct it ??

if you cannot understand the question or have anything you want to ask me please comment i will try to explain it.

rac cool
  • 117
  • 1
  • 1
  • 7

1 Answers1

4

You are assigning the absolute-values of the FFT result to y, hence you get REAL values. Doing ifft() on that simply assumes imaginary-parts are zero, hence the phase-shift.

S.C. Madsen
  • 5,100
  • 5
  • 32
  • 50
  • 3
    The result of the FFT is a complex number, you need both phase and module to invert it, if you use the absolute value you are loosing information. You can use the absolute value to graph it but be careful to don't use the absolute value for the IFFT. – Niles Jun 22 '16 at 09:26
  • but to set constraint for filter i have to use absolute values . is there any other way i can use fft to filter without having to use absolute values?? if so please give me the source. – rac cool Jun 22 '16 at 09:43
  • or can i compenstate the phase-shift some how (without knowing the orginal wave) – rac cool Jun 22 '16 at 09:45
  • Yes, you can compensate. But the compensation value is contained in the complex FFT result, not the absolute value. So don't throw that part away. – hotpaw2 Jun 23 '16 at 00:59