Issues with understanding and interpreting single dimension FFT

8 views (last 30 days)
Greetings,
I am trying to get the FFT from a powermeter trace I acquired, but I seem to be doing it wrong and/or can't interpret the results.
My dataset is named Pm and has 720 points, separated by 10 seconds, for a total duration of 7200 seconds. I can provide the data vector if necessary, but it is just a simple vector.
Here are my questions.
  1. Why is the amplitude at 0Hz so high? I do not see this artefact in MATLAB's example of an FFT.
  2. Why is there an offset in the amplitude? I would expect the signal to hover around 0 in general.
  3. Based on visual inspection of the trace, I would expect a peak at around 0,0016Hz. I can see that there is a modulation of around 10 minutes in the trace.
Any help would be appreciated.
Here is the code I am using.
% This is to plot the data in units of time. I am using the following code from someone else to plot the moving average.
% The black curve is the moving average and the green points are the complete dataset.
figure
plot(Pm,'g.');
hold on;
plot(moving(Pm,7),'k');
legend('Pm','7pt moving mean')
xlabel('Temps / 10 (s)')
ylabel('P (mW)')
% This is the FFT part.
figure
Fs = 1/10; % Sampling frequency
T = 1/Fs; % Sampling period
L = length(Pm); % Length of signal
t = (0:L-1)*T; % Time vector
F = fft(Pm);
F2 = abs(F);
F3 = log(abs(F/length(Pm)));
P2 = abs(F/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs/L*(0:(L/2));
plot(f,P1);
xlabel("f (Hz)")
ylabel("|fft(Puissance)|")
figure
plot(Fs/L*(0:L-1),F3);
xlabel("f (Hz)")
ylabel("log[|fft(Puissance)|]")
% FFT plot
% Zoom in of the FFT plot

Accepted Answer

Star Strider
Star Strider on 24 Sep 2024
Edited: Star Strider on 24 Sep 2024
It would help to have your data.
1 The 0 Hz value is high because that represents the mean of the time-domain signal. If you subtract the mean from the signal and then calculate the Fourier transform, the 0 Hz compionent goes to zero (or close to it). I do this routinely in order to avoid hiding the other peaks.
2. I’m not certain what you’re referring to.
3. I don’t have your signal. Subtracting the mean and then calculatting the Fourier transform could reveal the other ‘hidden’ peaks. Otherwise, witth a sampled siignal, the sampling introduces artifacts. These are less prominent at faster (higher) sampling frequencies, however essentially unavoidable. Also, windowing the signal could reveal more information, as could zero-padding it (using the length parameter) to increase the frequency resolution.
.
EDIT — (24 Sep 2024 at 18:31)
Note that the fft function assumes that the sampling intervals are regular and constant. If they aren’t, use the resample function to force them to be.
I usually use it as:
Fs = 1/mean(diff(t)); % Sampling Frequency, ‘t’ Is The Time Vector Corresponding To The Signal Samples
[sr,tr] = resample(s, t, Fs); % Return The Resampled Signal And Corresponding Time Vector
.
  4 Comments
Patrick Soucy
Patrick Soucy on 24 Sep 2024
Greetings,
Thank you very much for your answer. I will take the time to read your modified code for the FFT.
If I understand correctly, I was basically doing it fine, but your code diminished the artefact at 0Hz, making it easier to visualize.
I think I see what you mean that substracting the mean is what fixes this issue. Is this therefore a standard procedure for signal processing?
You mentioned two things in your original answer, windowing and zero padding (using the length parameter). What are those?
  1. For windowing, do you mean doing the FFT on the moving average data (my black curve) instead of the original data? I am definitely going to do that, as the trend is more obvious there.
  2. For zero padding, I would just add zeroes at the end of my vector, and recalculate the FFT?
Again, thank you very much.
Star Strider
Star Strider on 24 Sep 2024
My pleasure!
Is this therefore a standard procedure for signal processing?
I am not certain that it is standard, although it is definitely recommended, for the reason I stated.
  1. No. In my ‘FFT1’ function, I use the hann window. The purpose of windowing is to correct for the fft being finite, instead of infinite as is the formal definition of the Fourier transform. Windowing produces a better and more representative spectrum result.
  2. That is one option. Here, I use the second argument to speciify the length of the fft. Making it a power-of-2 makes the fft calculation more efficient.
My pleasure!
.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!