[Math] matlab problem – removing frequencies after FFT, signal processing

fourier analysisMATLABsignal processing

I want to stress that this is not a coding problem, my problem is that i don't fully understand the mathematics surrounding the subject and that's why I believe I have a problem.

I was given an assignment to choose a song (I chose the song Stricken by disturbed), perform fast fourier transform on the song, this will shift us from time domain to frequency domain.

Now I was asked to remove the first $10000$ frequencies. if $f(t)$ describes the signal of the song, and $\hat f(u)$ describes the fourier transform of the signal, then define $\hat g(u)$ such that $g(u)=0$ for all $u \in [0,10000]$ and $\hat g(u)=\hat f(u)$ otherwise.

After I removed the first $10000$ frequencies, I was asked to do something else that the teacher kept hidden from us and wanted us to figure out ourselves what we need to do, then perform an inverse fourier transform on $\hat g(u)$ to get $g(t)$. If the hidden action was performed correctly, than $g(t)$ should be strictly real.

So the goal of this exercise is to find out what the hidden action is.

Here is what I think:

The problem with removing the first $10000$ frequencies is that the magnitude is no longer even.

We know for sure, that if $f(t)$ is strictly real, then $|\hat f(u)|$ is even.
For example, this is a graph of the magnitude of the fourier transform as a function of frequency, of the song i sampled

magnitude of fourier transform as function of frequency

Now if I change the first $10000$ values of the fourier transform, the magnitude of transform as function of frequency looks like

enter image description here

You can clearly see that now the magnitude is not an even function. So there is no way that the inverse transform will be a real function.

However, if we now also remove the last $10000$ frequencies, the magnitude should be an even function.

And the graph shows that it is. However, when I calculate the inverse transform, it is not a real function. So something is wrong or missing.

Here is the code that I wrote:

enter image description here

As you can see, after invoking the inverse fourier transform, i get a function that is not real. Why? What am I missing?

Best Answer

You are actually zeroing out the last $10001$ samples of the FT: length(490000:500000) = 100001. However, that's not the only problem. Remember that the first sample in the FFT is DC and that there is only one value for it. Thus, you want to zero out the last $9999$ samples of the FFT:

N = 500e3;
Nz = 10e3;
x = rand( N, 1 );
X = fft( x );
Xz = X;
Xz(1:Nz) = 0;
Xz(end-Nz+2:end) = 0;
xz = ifft( Xz );
whos xz
  Name           Size              Bytes  Class     Attributes

  xz        500000x1             4000000  double              

sum( imag( xz(:) ) )

ans =

     0
Related Question