MATLAB 代码来评估随时间变化的音频响度

信息处理 matlab 声音的
2022-02-21 15:16:08

谁能告诉我如何使用 MATLAB 随时间评估响度/强度?随时间变化的响度/强度指:在此处输入图像描述

在上图中,顶部的“黑色”是声音随时间变化的幅度,绿线是相应的响度/强度随时间变化下面的绿线是我想要的,是使用Praat生成的。

谁能告诉我,给定声音输入,如何使用 MATLAB随着时间的推移生成相应的响度/强度?

例如,给定一个输入,我可以使用这个 MATLAB 脚本生成上面的输入:

[x,fs] = audioread('soundfile.wav');
t = (0:length(x)-1)/fs;
subplot(211);
plot(t,x);

那我怎样才能生成绿线呢?谢谢。

(ps。除 MATLAB 之外的任何其他编程语言也是受欢迎的)

1个回答

通常假定任何音频记录都具有与帕斯卡 (Pa) 成比例的单位。这是高于(正)或低于(负)环境压力的声波的瞬时压力。

(要真正从 WAV 文件中获取帕斯卡,您需要知道录音系统的校准系数。)

声音的响度(在空气中)通常以分贝为单位报告为声压级 (SPL)。SPL(以 dB 为单位)和帕斯卡相关为

Pa_ref = 20e-6; %reference pressure for SPL SPL_dB = 10*log10( (Pa / Pa_ref).^2 );

如果您使用瞬时压力值(即直接来自 WAV 文件的值),该等式将为您提供瞬时 SPL。根据您显示的图表,您不需要瞬时 SPL。您需要经过时间平滑的 SPL。

为了获得时间平滑的 SPL,标准方法是提取压力信号的包络。有很多方法可以做到这一点。一种方法是对信号进行整流和低通滤波。在这种情况下,您的处理可能如下所示:

%load and calibrate the data [wav,fs_Hz]=audioread(myfilename); %load the WAV file my_cal_factor = 1.0; %the value for your system to convert the WAV into Pascals wav_Pa = wav * my_cal_factor; %extract the envelope smooth_sec = 0.125; %"FAST" SPL is 1/8th of second. "SLOW" is 1 second; smooth_Hz = 1/smooth_sec; [b,a]=butter(1,smooth_Hz/(fs_Hz/2),'low'); %design a Low-pass filter wav_env_Pa = sqrt(filter(b,a,wav_Pa.^2)); %rectify, by squaring, and low-pass filter %compute SPL Pa_ref = 20e-6; %reference pressure for SPL in Air SPL_dB = 10.0*log10( (wav_env_Pa ./ Pa_ref).^2 ); % 10*log10 because signal is squared %plot results figure; subplot(2,1,1); t_sec = ([1:size(wav_Pa)]-1)/fs_Hz; plot(t_sec,wav_Pa); xlabel('Time (sec)'); ylabel('Pressure (Pa)'); subplot(2,1,2) plot(t_sec,SPL_dB); xlabel('Time (sec)'); ylabel('SPL (dB)'); yl=ylim;ylim(yl(2)+[-80 0]);