我正在使用mpiir_l2()用户Matt L的博士论文来设计 IIR 滤波器。我将分子和分母系数的数量都设置为相同的值(在和)。最大磁极半径为. 我的观察是结果实际上是一个 FIR 滤波器,分母系数总是. 基本上,结果等于lslevin()同一来源的最小二乘 FIR 设计的函数。
显然,我的滤波器规范中的某些内容使 FIR 解决方案比任何 IIR 滤波器具有更好的错误。该规范是数值优化的结果,在人眼看来非常随机,所以我不确定要寻找哪些属性。
有没有办法从这个函数中得到一个真正的 IIR 滤波器?我想比较相同规格的 IIR 和 FIR 滤波器,看看哪个更好。现在,当结果基本相同时,我真的无法比较。
编辑:这是一个示例脚本和相应的所需响应。看来我必须为此使用第三方托管网站,抱歉。
close all;
clear all;
% loads the specification, weights and frequencies as three vectors
% the sepcification has a relevant band that is padded with zeros to both
% sides. There is a "don't care" gap between the relevant band and the
% zeros.
load 'desiredResponse.mat' % loads Ws, freqs, desiredResponse
% search area
allowedOrder = 1:1:3; % numerator and denominator order
allowedShifts = 0:0.125:2; % linear phase term
% other variables
Fs = 48000;
normalFreqs = freqs / Fs * 2 * pi; % normalized frequencies
poleRadius = 0.98;
% preallcoate for the search
lowestError = inf;
bestNum = [];
bestDenom = [];
errors = zeros(length(allowedOrder), length(allowedShifts));
orders = zeros(length(allowedOrder), length(allowedShifts));
shifts = zeros(length(allowedOrder), length(allowedShifts));
% search for best aproximation
for nl = 1:length(allowedOrder)
ord = allowedOrder(nl);
for ns = 1:length(allowedShifts)
orders(nl, ns) = ord;
shifts(nl, ns) = allowedShifts(ns);
% add the linear phase shift
phaseShiftTerm = exp(-1i * shifts(nl, ns) * (ord-1)/2/Fs * 2 * pi * freqs);
D = desiredResponse .* phaseShiftTerm;
% design the filter (change denominator order here, if you like)
[num,denom] = mpiir_l2(ord, ord, normalFreqs, D, Ws, poleRadius);
% calculate filter response
H = freqz(num, denom, freqs, Fs);
% calculate the weighted error
errors(nl, ns) = sum(Ws .* abs(H - D).^2);
if errors(nl, ns) < lowestError
lowestError = errors(nl, ns);
bestNum = num;
bestDenom = denom;
end
end
end
