如何在Matlab中比较具有不同采样频率的两个音频信号?

时间:2016-05-04 01:09:27

标签: matlab audio signal-processing

我试图更好地理解上采样和下采样,并且正在使用音频信号来执行此操作。我开始时的基本采样率为66.15kHz,上采样为2,通过LPF运行(采样率为66.15kHz,截止频率为一半),然后下采样为2。

为了可视化初始信号和最终信号之间的差异,我创建了两个具有不同采样频率的频谱图。有很多明显的相似之处,以及较低频率版本中信号周围的更紧密的波段(由于上采样?),但我认为最好的办法就是采取某种减法图像。问题是矩阵的大小不同,因此我无法使用herehere找到的方法。

我是否应该将它们两者上采样到相同的尺寸?差异仍然存在吗?

有问题的光谱图:

Spectrograms

这里是我使用的代码,有些部分被注释掉,可能有助于在整个过程中形象化:

%clc, clear all, close all;

NFFT = 1:10:4000; % used like F in the spectrogram fxn
WINDOW = 2000;
NOVERLAP = 0;

preupsample = audioread('audioclip.wav');
Fo = 66150;
orig_nyq = Fo/2;
U = 2;
D = 3;
postupsample = upsample(preupsample, U);

[preLPF, ~, W] = myfft(postupsample,U*Fo,length(postupsample));

% figure, plot(W,mag2db(abs(preLPF))), xlabel('Frequency (Hz)'), ylabel('Magnitude Response (dB)');
% title('Magnitude Response after upsampling');

filterorder = 100;
Fpass = orig_nyq;
Fs = U*Fo;
Rpass = 0.00057565; % .1dB passband ripple
Rstop = 1e-4; % -80dB stopband attenuation
LPF = firceqrip(filterorder,Fpass/(Fs/2),[Rpass Rstop],'passedge');
% fvtool(LPF,'Fs',Fs,'Color','White');

filtered_upsample = filter(LPF,1,postupsample);
[postLPF, ~, W] = myfft(filtered_upsample,U*Fo,length(filtered_upsample));
% figure, plot(W,mag2db(abs(postLPF))), xlabel('Frequency (Hz)'), ylabel('Magnitude Response (dB)');
% title('Magnitude Response after applying LPF');

postdownsample = downsample(filtered_upsample,D);
[postDS, w, W] = myfft(postdownsample,U*Fo/D,length(postdownsample));
% figure, plot(W,mag2db(abs(postDS))), xlabel('Frequency (Hz)'), ylabel('Magnitude Response (dB)');
% title('Magnitude Response after downsampling');

%[~,F1,T1,P1]=
figure, spectrogram(preupsample(:,1),WINDOW,NOVERLAP,NFFT,Fo,'yaxis');
%[~,F2,T2,P2]=
figure, spectrogram(postdownsample(:,1),WINDOW,NOVERLAP,NFFT,Fo*U/D,'yaxis');
% surf(T2,F2,10*(log10(abs(P2))-log10(abs(P1))),'edgecolor','none');
% view(90,-90);
% axis tight;

myfft.m的内容:

function [X, w, W] = myfft(x, F, N)
    X = fftshift(fft(x, N));
    w = fftshift((0:N-1)/N*2*pi);
    w(1:N/2) = w(1:N/2) - 2*pi;
    W = F*w;
end

0 个答案:

没有答案