help-octave
[Top][All Lists]

## Re: zp2sos error: cplxpair: could not pair all complex numbers

 From: Ozzy Lash Subject: Re: zp2sos error: cplxpair: could not pair all complex numbers Date: Thu, 5 Jan 2017 22:44:38 -0600

On Thu, Jan 5, 2017 at 1:30 PM, Ozzy Lash wrote:
I'm not sure that it is a problem in bilinear, it may be in sftrans.  If you do the pre-warping that is done in the cheby2 function for the digital case, and then run cheby2 with the "s" flag, the zeroes that result also don't pass the cplxpair test, unless you raise the tolerance to about 400*eps

Looking a bit deeper, I think that the issue may be in the way the zeros of the nth order chebychev type 2 filter are being calculated.  The zeros of the prototype, while they successfully can be paired with cplxpair, they are not complex conjugates.

For the case of an even order, the zeros are calculated pretty simply as:

theta = pi*([1:n]-0.5)/n

z=1i./cos(theta)

In the odd order case, the zero at pi/2 is omitted, so it is a little more complex.

for n=6, you get:

>> n=6
n =  6
>> theta=pi*([1:n]-0.5)/n
theta =

Columns 1 through 4:

0.261799387799149   0.785398163397448   1.308996938995747   1.832595714594046

Columns 5 and 6:

2.356194490192345   2.879793265790644

>> z=1i./cos(theta)
z =

Columns 1 and 2:

0.00000000000000 + 1.03527618041008i   0.00000000000000 + 1.41421356237309i

Columns 3 and 4:

0.00000000000000 + 3.86370330515627i  -0.00000000000000 - 3.86370330515628i

Columns 5 and 6:

-0.00000000000000 - 1.41421356237310i  -0.00000000000000 - 1.03527618041008i

>> cplxpair(z)
ans =

Columns 1 and 2:

-0.00000000000000 - 1.03527618041008i   0.00000000000000 + 1.03527618041008i

Columns 3 and 4:

-0.00000000000000 - 3.86370330515628i   0.00000000000000 + 3.86370330515627i

Columns 5 and 6:

-0.00000000000000 - 1.41421356237310i   0.00000000000000 + 1.41421356237309i

instead of calculating all of the zeros, I wonder if it would make sens to calculate the zeros for values of theta from 0 up to but not including pi/2, and then conjugating those zeros, so that all of the zeros are complex conjugate pairs.

Here is a patch that makes this change.

--- /home/lash/octave/signal-1.3.2/cheby2.m    2017-01-05 22:10:48.630452347 -0600
+++ cheby2.m    2017-01-05 22:37:24.415014904 -0600
@@ -113,10 +113,11 @@
beta = cosh (phi) * cos (theta);
if (rem (n, 2))
## drop theta==pi/2 since it results in a zero at infinity
-    zero = 1i * C ./ cos (theta([1:(n - 1) / 2, (n + 3) / 2:n]));
+    zero = 1i * C ./ cos (theta([1:(n - 1) / 2]));
else
-    zero = 1i * C ./ cos (theta);
+    zero = 1i * C ./ cos (theta([1:n/2]));
endif
+  zero = [zero, conj(zero)];
pole = C ./ (alpha.^2 + beta.^2) .* (alpha - 1i * beta);

## Compensate for amplitude at s=0

Is there a bug report for this issue?  I can add this to the bug report if so.

I'm not sure that this is the best solution, and there may be issues with the poles as well as the zeros.

Bill