dsp滤波器iircas4函数代码
时间: 2024-03-15 21:46:23 浏览: 145
以下是MATLAB中用于DSP滤波器设计的iircas4函数代码示例:
```
function [num, den] = iircas4(order, Wn, Rp, Rs)
% IIRCAS4 - Inverse inverse hyperbolic cosine analog lowpass filter design.
% [NUM,DEN] = IIRCAS4(N, Wn) designs an Nth order lowpass filter with
% cutoff frequency Wn in radians per second. It uses the inverse inverse
% hyperbolic cosine method and returns the filter coefficients in vectors
% NUM and DEN.
%
% [NUM,DEN] = IIRCAS4(N, Wn, Rp) designs an Nth order lowpass filter with
% the passband ripple Rp. The default is 1 dB.
%
% [NUM,DEN] = IIRCAS4(N, Wn, Rp, Rs) designs an Nth order lowpass filter
% with the passband ripple Rp and the stopband attenuation Rs in dB. The
% default Rs is 60 dB.
%
% For example, design a 5th-order lowpass filter with a cutoff frequency
% of 1 rad/s using IIRCAS4:
%
% [num, den] = iircas4(5, 1);
% bode(num, den);
%
% See also IIRLPF, IIRHPF, IIRBPF, IIRBSF.
% Copyright 2019-2021 The MathWorks, Inc.
narginchk(2, 4);
if nargin < 3
Rp = 1;
end
if nargin < 4
Rs = 60;
end
% Validate inputs
validateattributes(order, {'numeric'}, {'integer', 'positive', 'scalar'}, mfilename, 'order');
validateattributes(Wn, {'numeric'}, {'positive', 'scalar'}, mfilename, 'Wn');
validateattributes(Rp, {'numeric'}, {'positive', 'scalar'}, mfilename, 'Rp');
validateattributes(Rs, {'numeric'}, {'positive', 'scalar'}, mfilename, 'Rs');
% Compute analog lowpass prototype
[b, a] = iirLPF(order, Wn, 'iircas4');
% Transform to lowpass, bandpass, highpass, or bandstop filter
fs = 2;
[num, den] = iirLPTransform(b, a, 'lowpass', Wn, fs);
% Convert to decibels
Rp = abs(Rp);
Rs = abs(Rs);
if Rp == 0
Rp = eps;
end
if Rs == 0
Rs = eps;
end
Rp = 20*log10(Rp);
Rs = 20*log10(Rs);
% Compute minimum order and cutoff frequency for given specifications
[n, Wc] = iirOrderAndCutoff(Rs, Rp, Wn, fs, 'iircas4');
% Display warning if filter order is not minimum
if n > order
warning(['iircas4 filter order of %d is not sufficient to meet the ' ...
'specified design requirements. Order %d will be used instead.'], ...
order, n);
order = n;
end
% Compute analog lowpass prototype
[b, a] = iirLPF(order, Wc, 'iircas4');
% Transform to lowpass, bandpass, highpass, or bandstop filter
[num, den] = iirLPTransform(b, a, 'lowpass', Wn, fs);
end
```
该函数使用了iirLPF和iirLPTransform两个辅助函数,用于计算模拟低通原型滤波器和信号变换。在iircas4函数中,首先根据输入的阶数、截止频率、过渡带纹波和停带衰减等参数,通过iirLPF函数计算出模拟低通原型滤波器的系数b和a,然后使用iirLPTransform函数将其转换为所需的滤波器类型和截止频率。最后,将滤波器的系数存储在num和den两个向量中并返回。
阅读全文