我有一组简单低通滤波器的幅度和相位数据。我可以使用Octave中的invfreqz成功地将滤波器拟合到复杂的频率响应中。但是,如果我希望以更高的采样率(例如4x)使用相同的数据来安装相同的滤波器呢?但是,在新的4x奈奎斯特频率之前,没有可用的幅度和频率数据。磁场和相位数据不能在较高频率下收集,因此必须通过其他方法或近似值进行加法。
将填充量和相位数据“入侵”到新的奈奎斯特频率的最简单方法是什么,以便invfreqz能够以新的采样率最有可能获得所收集的数据?
答案 0 :(得分:0)
这是我前一段时间写的一个函数,它可用于改变低通/带通滤波器的采样率(我从不打扰将它扩展到高通)。一般来说,你应该选择滤波器的响应几乎没有作为“切断”频率的点(我犹豫地说'截止',因为它不是正常意义上的截止);在此频率之上,响应设置为零。
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具有相同的截止值(你肯定会在阻带中获得更多的衰减和更多的线性相位)。