bugGNU Octave - Bugs: bug #40155, signal package: zp2sos return...

 
 

bug #40155: signal package: zp2sos return value is not compatible with Matlab

Submitter:  None
Submitted:  Tue 01 Oct 2013 01:17:39 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Mike Fontes Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.4
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 26 Jan 2014 09:47:48 PM UTC, comment #6: 

This bug is fixed with the following changeset:

http://sf.net/p/octave/signal/ci/f248ba

This fix will be part of the next signal package release.

Mike Miller <mtmiller>
Group Member
Wed 09 Oct 2013 03:32:00 AM UTC, comment #5: 

I had someone run the following in Matlab:


N=7;
Wn=.4;
res='low';
[a,b]=butter(N,Wn,res)
[z,p,k]=butter(N,Wn,res)
sos=zp2sos(z,p,k)
[sos,g]=zp2sos(z,p,k)


Here are the results. As I suspected, the return value of zp2sos depends on the number of output arguments. If the caller does not request the gain as a separate value, it is incorporated into the sos array.


a =

    0.0048    0.0339    0.1017    0.1695    0.1695    0.1017    0.0339    0.0048

b =

    1.0000   -1.3893    1.6750   -1.0539    0.5086   -0.1448    0.0263   -0.0020

z =

    -1
    -1
    -1
    -1
    -1
    -1
    -1

p =

   0.2550 + 0.7653i
   0.2550 - 0.7653i
   0.1664 + 0.2222i
   0.1664 - 0.2222i
   0.1940 + 0.4668i
   0.1940 - 0.4668i
   0.1584

k =

    0.0048

sos =

    0.0048    0.0048         0    1.0000   -0.1584         0
    1.0000    2.0000    1.0000    1.0000   -0.3328    0.0771
    1.0000    2.0000    1.0000    1.0000   -0.3880    0.2555
    1.0000    2.0000    1.0000    1.0000   -0.5101    0.6507

sos =

    1.0000    1.0000         0    1.0000   -0.1584         0
    1.0000    2.0000    1.0000    1.0000   -0.3328    0.0771
    1.0000    2.0000    1.0000    1.0000   -0.3880    0.2555
    1.0000    2.0000    1.0000    1.0000   -0.5101    0.6507

g =

    0.0048


Mike Miller <mtmiller>
Group Member
Wed 02 Oct 2013 12:03:26 AM UTC, comment #4: 

Note that zp2sos has two output arguments, the second output argument is the gain.

It may be that Matlab's zp2sos returns a different value for sos depending on whether one or two output arguments are requested. Octave's does not.

Mike Miller <mtmiller>
Group Member
Tue 01 Oct 2013 05:28:35 PM UTC, comment #3: 

would someone with matlab try this code:

N=7;
Wn=.4;
res='low';
 [Z,P,K]=butter(N,Wn,res);
 sos=zp2sos(Z,P,K)                    % Convert ZP to SOS

in Octave with this code I get:
N=7;
Wn=.4;
res='low';
 [Z,P,K]=butter(N,Wn,res);
 sos=zp2sos(Z',P',K)                    % Convert ZP to SOS


sos =

   1.00000   2.00000   1.00000   1.00000  -0.33284   0.07708
   1.00000   2.00000   1.00000   1.00000  -0.38797   0.25551
   1.00000   2.00000   1.00000   1.00000  -0.51008   0.65067
   1.00000   1.00000  -0.00000   1.00000  -0.15838   0.00000

Doug Stewart <dastew>
Tue 01 Oct 2013 04:19:02 PM UTC, comment #2: 

I think the problem is in the filter functions

The error line is:
sos=zp2sos(Z,P,K);                      % Convert ZP to SOS

when I change it to
sos=zp2sos(Z',P',K);                      % Convert ZP to SOS
then it is OK.

the zp2sos is expecting  column vectors but the filter designs
are giving row vectors. Matlab says the they use column vectors.

I did not look at the gain problem yet.
Doug

Doug Stewart <dastew>
Tue 01 Oct 2013 01:51:43 PM UTC, comment #1: 

Hi Mike, you have posted to the Octave bug tracker, but your message seems more suited to the help list (help-octave@octave.org). You have not identified a specific bug, not that there aren't any bugs in the signal package. There are probably at least 2 bugs at work here. Our goal is indeed to make the signal package compatible with Matlab.

I can confirm your results by running the attached script, but that's as far as I've gone with it.

Please ask your question on the help mailing list instead, which is read by many more people who can better help you with what you are working on.

I'll leave this open for now, but there is not much that can be done here until you can identify which particular function(s) are giving different results from Matlab. Please do try to find those differences if you want to help improve the quality of the Octave signal package.

Mike Miller <mtmiller>
Group Member
Tue 01 Oct 2013 01:17:39 PM UTC, original submission:  

I am using the eziir32.m script designed by TI to create iir filter coefficients for use with the TI libraries.  They were designed to run under Matlab, but they also run under Octave, using the signals package.  There are two problems I have noticed:

1. Some runs of the script cause errors in the Octave environment and produce valid results in the Matlab environment.

2. Some runs of the script produce valid, but very different results in the two environments.

My big issue is with choice number 2 because the results are very different, and are causing representation and overflow issues in the code written using the libraries.  I have attached a file which contains the results of a Matlab and an Octave run for the same script inputs. The Matlab run normalizes the filter gain to 1 and scales the coefficients accordingly.  The Octave run gives me a gain of over 1100 and totally different coefficients.

I need to get the normalized output to keep the filter representation from losing accuracy due to rounding. A few questions come to mind:

1. What is different between the two packages that cause the large differences in the results created?
 
2. Are there steps that can be taken to normalize the Octave output and supply a set of coefficients similar to those from Matlab? 

3. Is the signal package compatible with Matlab, or similar to Matlab when using the functions in the script.

Can someone please contact me to discuss this.  I do not have Matlab and I am relying on Octave to provide me with the coefficients for my filters.  I need to know how to successfully get workable values in a normalized form.

Sincerely,

Mike Fontes
-email is unavailable-

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #29279:  eziir32.m added by None (7KiB - application/octet-stream)
file #29280:  Octave and Matlab output and files for IIR.doc added by None (306KiB - application/msword)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dastew (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-01-26 mtmiller StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2013-10-09 mtmiller StatusNeed Info Confirmed
        SummaryOctave does not produce same results as Matlab for iir scripts signal package: zp2sos return value is not compatible with Matlab
    2013-10-01 mtmiller StatusNone Need Info
        Operating SystemMicrosoft Windows Any
    2013-10-01 None Attached File- Added eziir32.m, #29279
        Attached File- Added Octave and Matlab output and files for IIR.doc, #29280

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code