Design Elliptic IIR filter.
The resulting transfer function is returned in the state-space form with A,B,C,D variables.
Example 1
Design a discrete lowpass filter with transition band between 5..6 Hz, if the sampling frequency is 30 Hz. The stopband should have more then 40 dB attenuation and the passband should not have more then 0.1dB ripple.
uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit, IirFilters,
LinearSystems;
procedure TForm1.Button1Click(Sender: TObject);
var z,p, num,den, FreqFr,Response: Vector;
Order: integer;
k,Bw,Wc: TSample;
WcArray: TSampleArray; //modified 3dB frequency
begin
SetLength(WcArray,1);
Order := EllipticOrder([5/15,6/15],0.1,40,ftLowpass,WcArray,false);
EllipticFilter(Order,0.1,40,WcArray,ftLowpass,false,num,den);
FrequencyResponse(num,den,Response,64);
FreqFr := Ramp(response.Length,0,30*0.5/Response.Length);
DrawIt(FreqFr,20*Log10(Abs(Response)));
end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project
#include "MtxVecEdit.hpp"
#include "MtxVecTee.hpp"
#include "SignalUtils.hpp"
#include "IirFilters.hpp"
#include "LinearSystems.hpp"
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Vector z,p, num, den, FreqFr, Response, WcArray;
int Order;
double k,Wc,Bw;
WcArray->Size(1);
Order = EllipticOrder(OPENARRAY(double,(5.0/15,6.0/15)),0.1,40,ftLowPass,WcArray->PValues1D(0),WcArray->Length-1,false);
EllipticFilter(Order,0.1,40,WcArray->PValues1D(0),WcArray->Length-1,ftLowPass,false,num,den);
FrequencyResponse(num,den,Response,64);
FreqFr = Ramp(Response->Length,0,30*0.5/Response->Length);
DrawIt(FreqFr,20*Log10(Abs(Response)),"Frequency response",false);
}
using Dew.Math;
using Dew.Math.Editors;
using Dew.Math.Units;
using Dew.Signal;
using Dew.Signal.Units;
using Dew.Math.Tee;
using Dew.Signal.Tee;
private void button1_Click(object sender, EventArgs e)
{
Vector z = new Vector(0);
Vector p = new Vector(0);
Vector num = new Vector(0);
Vector den = new Vector(0);
Vector Response = new Vector(0);
double[] WcArray = new double[1];
int Order; //design a fifth order filter.
Order = IIRFilters.EllipticOrder(new double[2] { 5.0/15, 6.0/15 }, 0.1, 40, TFilterType.ftLowPass, ref WcArray, false); //design analog protype
IIRFilters.EllipticFilter(Order, 0.1,40, WcArray, TFilterType.ftLowPass, false, num, den, TIirFrequencyTransform.ftStateSpaceAnalog);
SignalUtils.FrequencyResponse(num, den, Response, 32, false, TSignalWindowType.wtRectangular, 0);
Vector FreqFr = MtxExpr.Ramp(Response.Length, 0, 30*0.5 / Response.Length); //X axis
TeeChart.DrawIt(FreqFr, Response, "Frequency response", false);
}
Declaration
Function EllipticFilter(Order: integer; PassRipple, StopRipple: TSample; const CutoffFreq: array of TSample; FilterType: TFilterType; Analog: boolean; z, p: TVec; var k: TSample; IirFrequencyTransform: TIirFrequencyTransform = ftStateSpaceAnalog): TSample;
Description
Design Elliptic filter of Order with CutoffFreq frequencies and of FilterType type. Set Analog to True, to request an analog filter design in s-plane or set it to false to obtain a digital filter design in z-plane. CutoffFreq must be in range between 0 and 1 (Sampling frequency = 2) in case of a digital filter design. IIrFrequencyTransform specifies when and how will the frequency band transformation be applied. PassRipple defines the passband ripple in dB and StopRipple defines the stopband ripple in dB. The resulting transfer function is returned in the zero-pole form, with z,p,k variables.
Declaration
Function EllipticFilter(Order: integer; PassRipple, StopRipple: TSample; const CutoffFreq: array of TSample; FilterType: TFilterType; Analog: boolean; num, den: TVec; IirFrequencyTransform: TIirFrequencyTransform = ftStateSpaceAnalog): TSample;
Description
The resulting transfer function is returned in the numerator/denumerator form with num and den.