Audition是音频工程师广泛使用的音频分析处理软件。Audition的频率分析模块能够得到音频序列的频谱图,通过编写matlab,实现类似Audition的结果。
大致思路是:对序列进行分帧,加窗,添加恢复系数,FFT,abs,平均。
保证matlab的结果与audition相同。
function [ mag, ang, freq ] = fft_average( filename, nfft, average_num )
%对输入信号进行分帧fft运算,并对fft结果进行平均
% OutPut:
% mag 幅度;
% ang 相位;
% freq 频率;
% Input:
% filename 输入音频文件的路径名;
% FS 采样率;
% nfft FFT的点数;
% average_num FFT分帧数
% Syntax:
% [ mag, ang, freq ] = fft_average( 'D:\03_media\01_audio\WLAN Direct\volume_5.wav', 4096, 1000)
% Fs = 48000;
% filename = 'D:\03_media\01_audio\WLAN Direct\volume_5.wav';
% nfft=512;
% average_num = 1000
disp('read file');
[Y,Fs] = audioread(filename, 'double');
fprintf('the sample rate is %d.\n', Fs);
ns=nfft;
audio_frames_num = length(Y(:,1))/ns;
if average_num > audio_frames_num
average_num = audio_frames_num;
end
average_num = audio_frames_num;
t=(0:1/Fs:(average_num*ns-1)/Fs)';
p_average = 0;
a_average = 0;
n_first = 1;
for index=1:average_num
xn=Y(n_first:n_first+ns-1,1);
wd = hann(ns);
xwd = 2*xn.*wd;
n_first = n_first+ns;
y = fft(xwd, nfft);
p2=abs(y/ns);
a1 = unwrap(angle(y));
p1=p2(1:nfft/2+1);
p1(2:end-1)= 2*p1(2:end-1);
p_average = p_average + p1;
a_average = a_average + a1;
end
f=(0:nfft/2)*Fs/nfft;
freq = f;
mag = 20*log10(p_average/average_num);
ang = a_average/average_num;
subplot(2,1,1);
plot(t,Y(1:average_num*nfft));hold on;
subplot(2,1,2);
plot(f, mag);
ylim([-96,0]);
xlim([10,20000]);
set(gca,'XScale','log')
end