Obtaining 2 highest peaks of spectrum in dB

3 ビュー (過去 30 日間)
Ashlyn McCann
Ashlyn McCann 2021 年 3 月 11 日
コメント済み: Mathieu NOE 2021 年 3 月 12 日
Pr= 20*(10^-6); %reference sound pressure level
n=length(y);
npoints= 2^nextpow2(n);
Ss = abs(fft(y)); % gets the spectrum, y is in Pa
SS = Ss/2
f = (0:n-1)*(fs/n); %gets x axis in frequencies
plot(f,SS)
[maxpks, maxloc]=findpeaks(SS(1:40000),'MinPeakProminence',5,'MinPeakDistance',50);
figure(1)
plot(f,(SS))
hold on
plot(f(maxloc), maxpks, 'r*')
sortpks=sort(maxpks);
[j,h]=size(sortpks);
h1=(sortpks(j)) %obtain highest peak
h2=(sortpks(j-1)) %obtain second highest peak
Pr= 20*(10^-6); %reference sound pressure level
H1 = (10*log10(h1.^2/Pr^2)) %convert to dB This value is double what it should be
H2 = (10*log10(h2.^2/Pr^2)) %convert to dB This value is just not picking up the value in dB of highest peak
H1H2 = (H1 - H2)
  1 件のコメント
Ashlyn McCann
Ashlyn McCann 2021 年 3 月 11 日
I can't seem to pick off the two highest values and correctly convert them to dB

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 3 月 11 日
hello again !
you should probably use findpeaks once the spectrum is in dB (my own preference)
otherwise , you have seen in your other post how to use it with sorting options
  6 件のコメント
Ashlyn McCann
Ashlyn McCann 2021 年 3 月 12 日
Oh that actually answers my question, I added that line to my code after doing the fft of my data. Thank you!
Mathieu NOE
Mathieu NOE 2021 年 3 月 12 日
OK

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by