matlab - 滤波后低频移位

标签 matlab audio filtering signal-processing

我正在尝试在Matlab中构建具有不同频段的滤波器。滤波之后,低频会延迟,如以下图像所示:

过滤之前:
Before filtering

过滤后:
After filtering

您能帮我理解为什么会这样吗?

我使用的代码如下:

    [x,Fs] = audioread('drum-loop.wav');

% define constants  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

ntaps = 255;                                                               % number of filter-taps

% sampling frequencies for each branch
fs_A = 48000;                   %
fs_B = 24000;                   %
fs_C = 6000;                    %
fs_D = 1500;                    %

% decimation for each branch
dec_A = 1;                      %
dec_B = 2;                      %
dec_C = 4;                      %
dec_D = 4;                      %

% decimation filters  - - - - - - - - - - - - - - - - - - - - - - - - - - -
% ref: https://es.mathworks.com/help/dsp/ref/mfilt.html
decfilter_B = mfilt.firdecim(dec_B);                                       % decimate signal for branch B
x_B = filter(decfilter_B, x);                                              % apply decimation filter

decfilter_C = mfilt.firdecim(dec_C);                                       % decimate signal for branch C
x_C = filter(decfilter_C, x_B);                                            % apply decimation filter

decfilter_D = mfilt.firdecim(dec_D);                                       % decimate signal for branch D
x_D = filter(decfilter_D, x_C);                                            % apply decimation filter

% interpolation filters   - - - - - - - - - - - - - - - - - - - - - - - - -
% ref: https://es.mathworks.com/help/dsp/ref/mfilt.html
intfilter_B = mfilt.firinterp(dec_B);                                      % decimate signal for branch B
intfilter_C = mfilt.firinterp(dec_C);                                      % decimate signal for branch C
intfilter_D = mfilt.firinterp(dec_D);                                      % decimate signal for branch D

% define filters  - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% refs:
% https://es.mathworks.com/help/signal/ref/fir1.html
% http://es.mathworks.com/matlabcentral/answers/17260-fir1-basic-question
% http://es.mathworks.com/help/pdf_doc/signal/signal_tb.pdf

ovlp1 = 1000;
ovlp2 = 500;
ovlp3 = 250;

% branch A: band pass filter.
coeff_A = [fs_B/2-ovlp1 (fs_A/2-1)]/(fs_A/2);
bp_A = fir1(ntaps,coeff_A);

% branch B: band pass filter.
coeff_B = [fs_C/2-ovlp2  (fs_B/2-1)]/(fs_B/2);
bp_B = fir1(ntaps,coeff_B);

% branch C: band pass filter.
coeff_C = [fs_D/2-ovlp3 (fs_C/2-1)]/(fs_C/2);
bp_C = fir1(ntaps,coeff_C);

% branch D: band pass filter.
coeff_D = (fs_D/2-1)/(fs_D/2);
bp_D = fir1(ntaps,coeff_D,'low');

% apply filters
x_A_f = filter(bp_A,1,x);
x_B_f = filter(bp_B,1,x_B);
x_C_f = filter(bp_C,1,x_C);
x_D_f = filter(bp_D,1,x_D);

% summation filter
y = x_A_f + filter(intfilter_B, x_B_f) + ...
    filter(intfilter_B, filter(intfilter_C, x_C_f)) + ...
    filter(intfilter_B, filter(intfilter_C, filter(intfilter_D, x_D_f)));
y = y/max(y);       % normalize

% % compute fft
figure;
subplot(3,1,1);
plot(x);
NFFT = 2^nextpow2(length(x));                                           % Next power of 2 from length of y (in samples)
Y = fft(x,NFFT)/Fs;     
f = Fs/2*linspace(0,1,NFFT/2+1);
subplot(3,1,2);spectrogram(x,blackman(128),60,128,1e3,'yaxis')
subplot(3,1,3);plot(f,2*angle(Y(1:NFFT/2+1))) 

% % compute fft
figure;
subplot(3,1,1);
plot(y);
NFFT = 2^nextpow2(length(y));                                           % Next power of 2 from length of y (in samples)
Y = fft(y,NFFT)/Fs;     
f = Fs/2*linspace(0,1,NFFT/2+1);
subplot(3,1,2);spectrogram(y,blackman(128),60,128,1e3,'yaxis')
subplot(3,1,3);plot(f,2*angle(Y(1:NFFT/2+1))) 

audiowrite('output.wav',y,48000);

最佳答案

您的滤波器正在引入相移。使用filtfilt而不是filter

关于matlab - 滤波后低频移位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32072002/

相关文章:

c - 使用 MATLAB 套接字读取 float

c++ - 如果最高有效字节的最高有效位为1,则样本为负

ios - 如何读取录制的音频(二进制)文件以在 iOS 中上传

Angular Material Datatable - 将过滤应用于自定义数据源

matlab - 在脚本中调用matlab脚本

c - MexFile 导致 "Assertion detected"错误 - mexfiles 中的 memcpy 有问题吗?

MATLAB-将函数句柄参数作为句柄传递给另一个函数

ios - AudioKit AKSequencer 不会在 iOS 10 上循环

python - 如何通过 2x2 平均内核对 Pandas 数据帧进行下采样

带替换的 Django 过滤器