I am not certain what you are doing, or what result you want.
One problem is that you also need to specify the x-values of the bars in your bar call:
bar(Fv(1:20), har_mag(1:20),0.4)
If you want to find all the relevant peaks and their frequencies, add these lines after your existing (posted) code:
[pks,locs] = findpeaks(har_mag, 'MinPeakProminence',0.5);
FreqPeaks = table(Fv(locs)', pks, 20*log10(pks), 'VariableNames',{'Freq', 'Amp', 'dB'})
figure
plot(Fv, 20*log10(har_mag))
hold on
plot(Fv(locs), 20*log10(har_mag(locs)), '+r')
hold off
grid
axis([0 1200 -15 60])
The ‘FreqPeaks’ table has all the identified peaks (linear and dB) and their associated frequencies.
Best Answer