How can I convert a .wav file to Pascals?

7 Ansichten (letzte 30 Tage)
Ferran Zafrilla Magraner
Ferran Zafrilla Magraner am 8 Sep. 2023
Beantwortet: Mathieu NOE am 22 Sep. 2023
I have a 1 kHz tone, which is calibrated at 94 dB re. 20 uPa, and I am asked to calculate a scale factor which, by multiplying any point of the normalised amplitude, converts it to Pascals.
So far I have this, but it is wrong:
% Load the calibration audio file
[calibration_audio, calibration_fs] = audioread('calsig_1k_94dB.wav');
[unknown_audio, unknown_fs] = audioread('pianochord1scaled_corrected.wav');
% Calculate the number of samples corresponding to the first 50 ms
num_samples = round(0.05 * calibration_fs);
% Extract the first 50 ms of each signal
calibration_signal_original = calibration_audio(1:num_samples, 1); % Assuming a single-channel file
music_signal_original = unknown_audio(1:num_samples, 1); % Assuming a single-channel file
% Create a time vector for the x-axis
time_vector = (0:(num_samples - 1)) / calibration_fs;
% Create a figure to display the signals
figure;
subplot(2, 2, 1);
plot(time_vector, calibration_signal_original);
title('Calibration Signal (Original)');
xlabel('Time (s)');
ylabel('Amplitude');
% Define the scale factor for calibration signal in pascals
RMS = sqrt(calibration_audio/num_samples);
calibration_scale_factor = (20e-6)*(10^(RMS/20));
% Scale the calibration signal
calibration_signal_scaled = calibration_audio(1:num_samples, 1) * calibration_scale_factor;
First, I convert the normalised amplitude to dB RMS with the RMS variable (which I assume is wrong) and then apply the formula to convert RMS to Pascals.
Once I have the scale factor, I can also convert a .wav piano chord to Pascals as well.

Antworten (2)

Mathieu NOE
Mathieu NOE am 22 Sep. 2023

Brahmadev
Brahmadev am 20 Sep. 2023
Hi Ferran,
I understand that you would like to convert '.wav' data into ‘Pascals’.
For calculation of RMS value of the calibration signal, the following approach can be used:
RMS = sqrt(mean(calibration_signal_original.^2));
To find the 'calibration_scale_factor', you can refer to the following code:
% Calculate the scale factor of the calibration signal
reference_spl = 94; % dB re. 20 uPa
reference_pressure = 20e-6; % 20 microPascals
calibration_scale_factor = 10^((reference_spl - 20 * log10(reference_pressure)) / 20);
Hence this new 'calibration_scale_factor' value can be used to convert the '.wav' values to ‘Pascals’ using:
audio_scaled = calibration_signal_original*calibration_scale_factor ;
I hope this provides you with relevant information on how to convert '.wav' values into 'Pascals'.
Best regards,
Brahmadev

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by