Suppose you have some data that is a tone plus noise.
t=0:0.01:10;
y=sin(t) + rand(1,length(t));
I am trying to knock down the tone peaks in the fft so that doing the ifft will result with just the noise data. My algorithm would be a for loop that loops through each index of the abs(fft) to look for a peak. If there is a peak, I would substitute that peak with a noisy datapoint instead.
Problem is, after the fft is done, in order to visualize the data, normally I would use plot(abs(fft)). However, to do ifft, the imaginary data is also needed. Thus, I’m not sure how exactly I would go about “knocking the peak down” or getting rid of it so that I can use the ifft function. I think I would have to work with the imaginary numbers.
Any suggestions? :X
Thank you for your help.
You will have to work with imaginary numbers, but I don’t see why that’s a problem. You can still look for the peaks using the magnitude (
abs) representation, but when you “knock them down” you will put in place another complex value. It’s up to you how you want to determine what this value should be – you could set it to zero, interpolate local frequencies, insert a random number…Edit re: your comment:
Don’t let imaginary numbers confuse you. They’re not really “imaginary” anyway! It’s just that to represent a sine wave at a given frequency, you need two values: magnitude and phase. Magnitude is what you’re used to looking at and it determines how much of a given frequency we have. Phase determines the shift relative to some point (e.g. t = 0), which is also very important. As an example take the FFT to signals (say a sine and a cosine wave) with the same frequency – the magnitudes will look the same, but the phase will be different! If we didn’t have phase, IFFT wouldn’t know whether to give us a sine wave or a cosine wave, or something in between.
Of course, magnitude and phase are not the same thing as real and imaginary, but there is a simple formula to convert them. Either way we’re using two numbers to represent each frequency.