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 h =
new Vector(0);
Vector response =
new Vector(0);
Vector x =
new Vector(0);
double FS = 2;
int n = 41;
//lowpass design with cutoff frequency
SignalUtils.FirImpulse(h.Size(n),
new double[1] {0.5}, TFilterType.ftLowpass,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
x =
MtxExpr.Ramp(response.Length, TMtxFloatPrecision.mvDouble, 0, 1.0/response.Length);
MtxVecTee.DrawIt(x,response,"Lowpass with cutoff at 0.5",
false);
//lowpass design with transition band
SignalUtils.FirImpulse(h.Size(n),
new double[2] {0.3,0.5}, TFilterType.ftLowpass,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response,"Lowpass with transition band: 0.3-0.5",
false);
//Highpass design with cutoff frequency
SignalUtils.FirImpulse(h.Size(n),
new double[1] {0.5}, TFilterType.ftHighpass,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response,"Highpass with cutoff at 0.5",
false);
//Highpass design with transition band
SignalUtils.FirImpulse(h.Size(n),
new double[2] {0.3,0.5}, TFilterType.ftHighpass,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response,"Highpass with transition band: 0.3-0.5",
false);
//Bandpass design with transition bands
SignalUtils.FirImpulse(h.Size(n),
new double[4] {0.3,0.4,0.5,0.6}, TFilterType.ftBandpass,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response,"Bandpass with transitoin band: 0.3-0.4, 0.5-0.6",
false);
//Bandstop design with transition bands
SignalUtils.FirImpulse(h.Size(n),
new double[4] {0.3,0.4,0.5,0.6}, TFilterType.ftBandstop,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response,"Bandstop with transition bands: 0.3-0.4, 0.5-0.6",
false);
//Hilbert III
SignalUtils.FirImpulse(h.Size(n),
new double[1] {0}, TFilterType.ftHilbertIII,FS);
SignalUtils.FrequencyResponse(h,
null,response,8,
false,TSignalWindowType.wtRectangular,0);
MtxVecTee.DrawIt(x,response,"Hilbert III",
false);
//Hilbert IV
n++;
//n must be even
SignalUtils.FirImpulse(h.Size(n),
new double[1] {0}, TFilterType.ftHilbertIV,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response,"Hilbert IV",
false);
//Differentiator III
n--;
// n must be odd
SignalUtils.FirImpulse(h.Size(n),
new double[1] {0}, TFilterType.ftDifferentiatorIII,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response, "Differentiator III",
false);
//Differentiator IV
n++;
//n must be even
SignalUtils.FirImpulse(h.Size(n),
new double[1] {0}, TFilterType.ftDifferentiatorIV,FS);
SignalUtils.FrequencyResponse(h,
null, response, 8,
false, TSignalWindowType.wtRectangular, 0);
MtxVecTee.DrawIt(x,response, "Differentiator IV",
false);
}