How to plot spectral density given a column of data?
1 view (last 30 days)
Show older comments
My question is how do I plot the spectral density? The data itself is associated with an error trajectory which is equal to the difference between an optimal trajectory and a less ideal trajectory. The data itself already was polled at a rate of Ts = .034s and is time stamped. I thought it would be as simple as taking that column of data applying fft and then plot(abs(x)) in order to apply the fourier transform to find the predominant frequencies? But the graph seems to not show me anything interesting.
xfft = fft(x);
plot(abs(x));
title('Fourier Transform');
xlabel('Frequency');
ylabel('Magnitude');
0 Comments
Answers (1)
Star Strider
on 17 Sep 2020
My guess is that there is a significant d-c (constant) offfset. This is the mean of ‘x’, and will show up as the amplitude at 0 Hz.
Using this to plot it might be a bit more revealing:
Fs = 1/0.034; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
L = numel(x); % ‘x’ Is A Vector
xm = mean(x);
xfft = fft(x - xm)/L; % Subtract Mean & Normaloise By ‘L’
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(xfft(Iv))*2)
grid
xlabel('Frequency (Hz)')
ylabel('Magnitude')
.
3 Comments
Star Strider
on 17 Sep 2020
If you eliminated the d-c offsset, then you have at least two frequencies that could be significant, both less than 0.5 Hz. If you have the Signal Processing Toolbox, use the findpeaks function to get more information from them, and other peaks that may be of interest.
With respect to the sampling frequency, I can’t determine that. A sampling frequency of 29 Hz may be high enough for some applications, not high enough for others. Note that for best results, the sampling interval must be constant. If it isn’t, use the resample function to resample it to a constant sampling frequency.
See Also
Categories
Find more on Pulsed Waveforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!