声压级 谱 1/3 倍频程 matlab代码
时间: 2023-05-12 14:01:47 浏览: 951
声压级:声压级是指声音的强度程度,通常用分贝(dB)来表示。分贝越高,声音就越响。
谱:谱是指信号在频域上的表示,一般包括幅度谱和相位谱。
1/3 倍频程:在信号处理中,1/3 倍频程是指信号的有效频率范围,在此范围内信号能够被恰当地采样。
Matlab 代码:
1.计算声压级:
function SoundPressureLevel = SoundPressureLevelCalculator(y, y_reference)
% y:音频信号
% y_reference:参考音量
% 将音频信号转换为可选的区间内零平均值
y = y - mean(y);
% 音频信号的RMS幅值
RMS = sqrt(mean(y.^2));
% 计算参考音量的声压级
y_reference = y_reference - mean(y_reference);
RMS_reference = sqrt(mean(y_reference.^2));
SoundPressureLevel_reference = 20*log10(RMS_reference/20e-6); % dB SPL
% 计算音频信号的声压级
SoundPressureLevel = 20*log10(RMS/20e-6) - SoundPressureLevel_reference; % dB
2.计算频域谱:
function [amplitude_spectrum, frequency_axis] = FrequencySpectrumCalculator(y,fs)
% y:音频信号
% fs:信号的采样率
% 快速傅里叶变换
L = length(y);
Y = fft(y);
P2 = abs(Y/L);
amplitude_spectrum = P2(1:L/2+1);
amplitude_spectrum(2:end-1) = 2*amplitude_spectrum(2:end-1);
frequency_axis = fs*(0:(L/2))/L;
3.计算1/3倍频程:
function thirdOctaveBandFrequencies = ThirdOctaveBandFrequencies(frequencyRange, numBands)
% frequencyRange:频率范围
% numBands:数量
% 以3为底的对数计算,计算频率范围的的上限和下限
lowerFrequencyLimit = 2.^(-1/6)*frequencyRange(1);
upperFrequencyLimit = 2.^(1/6)*frequencyRange(2);
% 计算频带的边界
thirdOctaveBandFrequencies = zeros(1, numBands);
thirdOctaveBandFrequencies(1) = lowerFrequencyLimit*sqrt(2);
for ii = 2:numBands
thirdOctaveBandFrequencies(ii) = thirdOctaveBandFrequencies(ii-1)*sqrt(2);
end
thirdOctaveBandFrequencies(thirdOctaveBandFrequencies > upperFrequencyLimit) = [];
thirdOctaveBandFrequencies = [lowerFrequencyLimit, thirdOctaveBandFrequencies, upperFrequencyLimit];
阅读全文