这是我不久前编写的一个函数,可用于改变低/带通滤波器的采样率(我从来没有费心将其扩展到高通)。一般来说,您应该选择滤波器响应几乎为零的点作为“截止”频率(我不敢说“截止”,因为它不是正常意义上的截止);高于此频率,响应设置为零。
function [b, a, fNew, HNew, fOld, HOld, HCut] = ...
shiftFilterRate(b, a, fs1, fs2, order, fCut)
% SHIFTFILTERRATE Shift sampling rate of filter
%
% [bNew, aNew] = shiftFilterRate(b, a, fs1, fs2, order, fCut) designs a
% FIR filter of the given order to operate at sampling frequency fs2, in
% Hz, whose frequency magnitude characteristics match those of the filter
% whose coefficients are b, a, that operates at sampling rate fs1, in Hz.
% The function will only try to match the filter's magnitude in the
% region [0 fCut], in Hz.
%
% [bNew, aNew, fNew, HNew, fOld, HOld, HCut] = shiftFilterRate(...)
% returns additional parameters:
% fNew: The frequencies at which the designed filter's transfer
% function was evaluated (with resolution of 1 Hz)
% HNew: The transfer function of the designed filter
% fOld: The frequencies at which the existing filter's transfer
% function was evaluated (with a resolution of 1 Hz)
% HOld: The transfer function of the existing filter.
% HCut: The desired frequency response of the filter used as input
% to the function fir2.
%
% FIXME: Make this work for high pass filters.
%
if nargin < 5, fCut = inf; end
if nargin < 4, order = 50; end
%% Zero padding in frequency domain
res = 1; % Hz resolution
N1 = fs1 / res; % points at resolution before padding
% Original freq response
[H, f] = freqz(b, a, N1);
nanInd = find(isnan(H));
% Stabilise. NOTE: Will break if nanInd contains last elem or there are
% multiple NaNs in a row
H(nanInd) = H(nanInd + 1);
f = f / pi;
% Normalise cutoff freq
fCutNorm = fCut / (fs1 / 2);
% Cut frequencies above fCut, we don't really need them and it makes the
% FIR filter nasty
HCut = H;
HCut(f > fCutNorm) = 0;
% Create new freq response
NNew = ceil(fs2 / fs1 * length(HCut));
fNew = linspace(0, 1, NNew)';
HNew = [HCut; zeros(NNew - N1, 1)];
% Design filter
b = fir2(order, fNew, abs(HNew));
a = 1;
HOld = H;
fOld = f;
if nargout > 3
HNew = freqz(b, a, length(fNew));
end
请注意,在您的情况下,您可能希望将其设置为 -20 dB re 1,因为这似乎是您的滤波器提供的最大衰减。在那一点上:它看起来不是一个很好的过滤器......你有什么理由必须匹配这个响应?您可能最好只设计一个具有相同截止频率的 Butterworth(您肯定会在阻带中获得更多衰减和更多线性相位)。