Find maximum peaks in fft and power spectral density function

11 views (last 30 days)
I have an array ( raw_acceleration) of 1600 elements acquired every 10 seconds at 160Hz from a sensor. I use this array to calculate the fft and the Power Spectral Density and it works very well:
Fs=160;
raw_acceleration = u;
N = length(raw_acceleration);
xdft = fft(raw_acceleration);
xdft = xdft(1:floor(N/2+1));
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(raw_acceleration):Fs/2;
plot(freq,10*log10(psdx))
grid on
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')
I obtain this plot:
As you can see, I obtain four peaks centered around four different frequencies.
I would like to have a Matlab code which is able to automatically find these four maximum peaks and their frequency. At the moment, I always need to plot the graph and manually detect the maximum peak and its frequency.
Is there any way to do this by code? I hope you an help me.
I attached a sample of raw_acceleration array.

Answers (1)

Birdman
Birdman on 29 Mar 2018
  6 Comments
marcusbarnet
marcusbarnet on 29 Mar 2018
I tried to use max() function in Matlab, but I found out that it doesn't work as I would like..

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!