Plotting SPL(dBA) from an audio WAV file?

51 views (last 30 days)
ZHU z on 5 Apr 2022
Commented: Mathieu NOE on 12 Apr 2022
hi Mathieu NOE,thanks alot, again~
Please forgive me for posting a separate post in accordance with rik's comments.
I reviewed the code you gave me last time and the graph I obtained is shown in Figure 1.
and my questions is:
The vertical axis is all negative,and there is still a difference with the graph I want (Figure 2).and i notice the "sensor_spectrum_dB" in this code .Do you know what this means? can I generate SPL(dBA) by this "sensor_spectrum_dB"?
Please forgive me for asking a lot of questions, I found myself really not very good at this,
thanks a lot.
Looking forward to your reply~
% display 2 : averaged FFT spectrum
[freq, sensor_spectrum] = myfft_peak(signal,Fs,NFFT,OVERLAP);
% convert to dB scale (ref = 1)
sensor_spectrum_dB = 20*log10(sensor_spectrum);
% apply A weigthing if needed
if option_w == 1
pondA_dB = pondA_function(freq);
sensor_spectrum_dB = sensor_spectrum_dB+pondA_dB;
my_ylabel = ('Amplitude (dB (A))');
my_ylabel = ('Amplitude (dB (L))');
figure(2),semilogx(freq,sensor_spectrum_dB);grid on
df = freq(2)-freq(1); % frequency resolution
title(['Averaged FFT Spectrum / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(df,3) ' Hz ']);
xlabel('Frequency (Hz)');ylabel(my_ylabel);
figure 1
figure 2

Accepted Answer

Mathieu NOE
Mathieu NOE on 6 Apr 2022
hello Zhu
no problem, I'll try to answer as precisely as possible
the amplitude is negative because the dB scale is the log of the fft amplitude .
wav signals are by definition limited to +/- 1 amplitude (otherwise the signal is clipped) , so a max amplitude wav signal would never exceed 0 dB in the fft plot (because log(1) = 0)
so you need a "calibration" wav file that let you know by how much dB you must shift the vertical axis.
An example : in acoustics , the 0 dB reference level corresponds to 20 micro pascal acoustic pressure.
that is the 0 dB level in your figure 1 plot
Assuming you have "calibrated" your recorder and it says that a 60 dB ( = 1000 x 20 micro pascal) pressure sinus wave (for example at 100 or 1000 Hz) will be recorded as wav file with amplitude = 1 , so the dB level we computed must be shifted by + 60 dB (and that is the reason for the difference between the two plots).
so what we need now is another wav file that tells us waht is the factor between the amplitude in the wav file vs the real acoustic pressure
for the shape or spectral content of the file you provided, I can only say that it's really different from the plot you show in fig 1 , but what we get is truly what is inside the file - are you shure that the provided audio file should have a spectrum shape like fig 1 ?
all the best

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!