Plotting SPL(dBA) from an audio WAV file?
51 views (last 30 days)
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))');
df = freq(2)-freq(1); % frequency resolution
title(['Averaged FFT Spectrum / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(df,3) ' Hz ']);
Mathieu NOE on 6 Apr 2022
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