ar1st0crat / NWaves

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

Analog poles and zeros of elliptic filter are different from scipy #75

Open ToGoOrNotToGo opened 1 year ago

ToGoOrNotToGo commented 1 year ago

The analog poles and zeros of the elliptic filter are different from scipy. Is this a bug or there are different elliptic prototype design?

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.ellip.html#scipy.signal.ellip

ar1st0crat commented 1 year ago

Can you provide any particular examples? I took example from scipy docs:

z, p, k = signal.ellip(4, 5, 40, 100, 'low', output='zpk', analog=True)

This yields

>>> z
array([0.+273.40311861j, 0.+133.09448631j, 0.-273.40311861j,
       0.-133.09448631j])
>>> p
array([-16.5821937 -47.62311966j,  -3.98841045-96.14415841j,
       -16.5821937 +47.62311966j,  -3.98841045+96.14415841j])
>>>
>>> k
0.009999999999999992

Then I did the same thing in NWaves:

var poles = PrototypeElliptic.Poles(4, 5, 40);
var zeros = PrototypeElliptic.Zeros(4, 5, 40);

This yields

// poles
-0.03988410446959738 + 0.9614415840538687 j
-0.16582193703773462 + 0.47623119659115304 j
-0.16582193703773465 + -0.4762311965911529 j
-0.03988410446959739 + -0.9614415840538687 j

// zeros
0 + -1.3309448630630392 j
0 + -2.73403118612638 j
0 + 2.7340311861263804 j
0 + 1.3309448630630392 j

Essentially, it's identical to scipy's results (in NWaves the gain k is not returned separately, it's already in zeros and poles):

>>> z * k
array([0.+2.73403119j, 0.+1.33094486j, 0.-2.73403119j, 0.-1.33094486j])
>>>
>>>
>>> p * k
array([-0.16582194-0.4762312j , -0.0398841 -0.96144158j,
       -0.16582194+0.4762312j , -0.0398841 +0.96144158j])
ToGoOrNotToGo commented 1 year ago

I worded that a bit confusingly. I didn't mean an analog filter, but a digital filter (poles and zeros are always analog!?). I know, analog filters are not supported in NWaves. b, a = ellip(13, 0.009, 80, 0.05, output='ba') This results in different values in a and b