Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Using fft & ifft to remove a dominant signal
Replies: 1   Last Post: Apr 28, 2014 8:50 PM

 Messages: [ Previous | Next ]
 Derek Goring Posts: 3,922 Registered: 12/7/04
Re: Using fft & ifft to remove a dominant signal
Posted: Apr 28, 2014 8:50 PM

On Tuesday, April 29, 2014 12:20:08 PM UTC+12, Jessica wrote:
> Hi, I'm using a data set that varies with a specific frequency and amplitude, but has an increasing baseline value. So, my wave looks something like sin(x)+x (with a bit more noise). I want to take the power spectrum of my wave using fft(), remove the dominant frequency, and use ifft() to get my signal back without the dominant frequency in it and then plot the new signal with the old wave. So what I've got is something like this. My problem is that I'm getting out a new signal that's a couple of orders of magnitude larger than my original and is shaped like a parabola, but also isn't the right length. It's half of the length of the original length minus the couple or points I set to NaNs.
>
>
>
> Co2_ML=Co2_ML(isnan(Co2_ML)==0); this is my original wave
>
> t_ML=t_ML(isnan(Co2_ML)==0)-1958; this is the time vector
>
>
>
> N= length(Co2_ML);
>
> fs=((1:N/2)/(max(t_ML)));
>
> Y=fft(Co2_ML(1:N/2));
>
> pw_srs=(abs(Y).^2)/N;
>
>
>
> %Finding peak in power spectrum
>
> noc=pw_srs(fs>.7 & fs<1.1);
>
> fsc=fs(fs>.7 & fs<1.1);
>
> sub=find(noc==max(noc));
>
> aa=find(fs==fsc(sub));
>
>
>
> %Taking peak and few surround points of signal and setting to NAN
>
> pw_srs(aa-2:aa+2)=NaN;
>
>
>
> %Redefining pw_srs to exclude NaNs...
>
> pw_srs=pw_srs(isnan(pw_srs)==0);
>
>
>
> %Attempt to get data set back without dominant frequenct.
>
> Co2_new=fftshift(ifft(pw_srs));
>
>
>
> %Attempt to plot original wave and new wave without dominant signal
>
> %plot(t_ML,Co2_ML,t_ML, Co2_new)

Hard to know where to start.......
1. You should take fft of the whole sequence, not half of it.
2. The resulting Y will have equal peaks at sub and at N+1-sub, both need to be set to zero.
3. You need to do ifft(Y), ie of the whole transform, not on the magnitude.
4. Why are you doing fftshift(ifft(pw_srs)) ? This recalculates the fft.
5. Why muck around with NaN? Why not just set to zero?
6. Did you know max has a second output? This is what you should use to find the peak.
7. Have you heard of Gibbs Phenomenon? Google it. Just zeroing out the Fourier transform data like that will probably cause ringing. You need to taper them off.
8.
9.

Date Subject Author
4/28/14 Jessica
4/28/14 Derek Goring