ar1st0crat / NWaves

.NET DSP library with a lot of audio processing functions
MIT License
462 stars 71 forks source link

Wrong elliptic filter ripple configuration #12

Closed ToGoOrNotToGo closed 5 years ago

ToGoOrNotToGo commented 5 years ago

The elliptic filter ripple configuration in FiltersForm.AnalyzeEllipticFilter is converted to magnitude Db. But in PrototypeElliptic.Poles and PrototypeElliptic.Zeros it is converted as power Db. So my suggestion is not to use Db here. Or I am wrong?

ar1st0crat commented 5 years ago

Hi! The code is based on this wonderful pdf: http://eceweb1.rutgers.edu/~orfanidi/ece521/notes.pdf. Take a look at derivations at page 2. For instance, -20log(Gp) = 10log(1 + eps^2). The right side is programmed, but it was derived from magnitude dB. Also, IIRC, I tested it - the method worked as expected. Maybe I'm missing something, though, but the code seems to be OK.

Also, in FiltersForm the code is:

var ripplePassDb = Utils.Scale.ToDecibel(1 / deltaPass);

because 20log(1/d) = -20log(d). So the code is similar to MATLAB code from the pdf.

ToGoOrNotToGo commented 5 years ago

Ah OK. So parameter "rippleStop" means the stopband ripple, in decibels (stopbandRipple) and parameter "ripplePass" means the stopband attenuation, in decibels (stopbandAttenuation)?

ar1st0crat commented 5 years ago

Not sure if I understood you correctly. Fig.1 at page 2 from the pdf should help (I'm using the same notation):

Passband gain: Gp Passband ripple (Gp in dB): Ap = -20log(Gp) = 20log(1/Gp) Stopband (attenuation) gain: Gs Stopband (attenuation) ripple (Gs in dB): As = -20log(Gs) = 20log(1/Gs)

Ap and As are passed as parameters to EllipticFilter constructor (i.e. values in dB).

This is what the notation is in the pdf. I like the term 'attenuation' better because this value defines the amplitude loss (not the max amplitude of fluctuations in stopband) according to Fig.1. And the passband gain (ripple) here means also the max amplitude loss compared to level=1.0. Often it has slightly different meaning - illustrated here (when the center of oscillations is at level 1.0 : { 1-d, 1+d }). This one is used in Remez class.

ToGoOrNotToGo commented 5 years ago

Thanks a lot! Yes, the different terms make it difficult to learn...