0
$\begingroup$

I have this code which interprets a few data points on magnetic field strength into a spectrum, as shown below:

c = fft(magfield);
c = c*2/n;
ca = abs(c);
dt = 1/fs;
f = (0:n-1)/(500*dt);

for i = 1:length(ca)
    if ca(i) > 0.002608
        ca(i) = 0; 
    end
end

spectrum = fftshift(ca);
plot(spectrum)
    

Where fs is 5e5 and n is 50000000. what i get is a graph which looks like the one below:

enter image description here

I have no idea how to interpret the spectrum, where the peak frequencies are and why this mirroring effect is happening. Could you guys please shed some light on what's going on?

Thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

Your field data is real (as in "not complex") and hence your spectrum is conjugate symmetric.

fftshift() rotates the spectrum so that 0 Hz is in the middle of the vector. Your x-axis on the plot should be fs*[-nFFT/2:nFFT/2-1]/nFFT; where $nFFT$ is the FFT length and $fs$ is the sampling rate.

Remember that time discrete signals are periodic in frequency the second half of the spectrum represents the negative frequencies.

$\endgroup$
7
  • $\begingroup$ Actually, FFT algorithms are not able to make assumptions. $\endgroup$ Apr 25, 2021 at 21:54
  • $\begingroup$ Thanks for your answer! If the x axis is conjugate symmetric does that mean I can just erase all values above the middle frequency? Also, Im having a bit of trouble understanding the code snippet you included - what do nfft and nffy represent? They're not recognised as functions on matlab. $\endgroup$
    – TomIce
    Apr 26, 2021 at 1:27
  • $\begingroup$ @Tomice. What Hilmar is saying is that, for real-valued FFT input sequences, the second half of the spectrum contain no information that is not already contained in the first half of the spectrum. $\endgroup$ Apr 26, 2021 at 9:49
  • $\begingroup$ @RichardLyons: thanks for the comment. I tried to rephrase this. $\endgroup$
    – Hilmar
    Apr 26, 2021 at 11:37
  • $\begingroup$ @TomIce: sorry, bad typing on my part. Fixed in the post $\endgroup$
    – Hilmar
    Apr 26, 2021 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.