int KaiserFirLength(DewArray<double> W, double Ripple, double FS = 2);
Estimate the length of a windowed FIR filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | W | DewArray<double> | |
| 2 | Ripple | double | |
| 3 | FS = 2 | double |
Returns the length of the FIR filter, windowed with the Kaiser window, where the maximum allowed ripple of the pass band is Ripple and sampling frequency is FS. The W array holds two parameters: the start and the stop of the narrowest transition band, relative to the specified sampling frequency.
The equation can be found in [1] p. 453, eq. 7.93. The length of the filter designed with kaiser window is about 10% bigger then the length of the filter with the same specifications designed with the remez algorithm. The ripple of the passband and the stopband attenuation of a FIR filter designed with a Kaiser window are related with the equations:
Att[dB] = -20*Log10(Ripple); Ripple = Exp10(Att/-20);
References:
[1] Discrete-time signal processing, Oppenheim and Schafer, Prentice-Hall, 1989.
#include "MtxExpr.h"
#include "Units.Math387.h"
#include "Units.SignalUtils.h"
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::Math387;
using namespace Dew::Signal;
using namespace Dew::Signal::Units::SignalUtils;
void Example()
{
Vector h(0);
Vector response(0);
double FS = 2;
double Ripple = 0.0001;
int n = KaiserFirLength(DewArray<double>{0.5, 0.6}, Ripple, FS);
n = EnsureRange(4, n, MaxFirLength);
if (n % 2 == 0)
{
n++; //must be odd, if passband at FS/2
}
FirImpulse(h.Size(n), DewArray<double>{0.5, 0.6}, TFilterType::ftHighpass, FS); //get impulse response
Kaiser(h, KaiserBetaFir(Ripple)); //apply Kaiser window
FrequencyResponse(h, nullptr, response, 8, false, TSignalWindowType::wtRectangular, 0); //zero padd by 8x
}