Vlad
Continuing from conclusion of previous aLOG.
It looked like foton.py is importing filters correctly with minimal error, and should be able to import data from a complete susmodel. Here I discuss issues that arose when I tried to do this.
Relevant gds svn subdirectories for source code to which I refer throughout:
- /trunk/GUI/filterwiz
- /trunk/SignalProcessing/IIRFilter
I attempted to plot the zpk data of the O2 susmodel with Python:
- Scipy is out of date in the control room computers (signal.freqs_zpk is missing for example). Considering python2.7 will be end-of-life in 2 months, LIGO will be forced to upgrade everything anyway at some point in the future.
- Working on my laptop is fine, but I find that all methods for calculating frequency response from zpk in Scipy attempt to converting ZPK to numerator/denominator (BA). This is done by calculating the polynomial coefficients from the given roots, and then evaluating the function a the frequency. This fails because the coefficients grow to infinity very quickly.
I attempted to plot the zpk data of the O2 susmodel with Matlab:
- I Can plot TF when given as ZPK.
- However, even Matlab cannot handle converting ZPK to BA, gives same infinate polynomial coefficients that I get in python, and gives an error.
- There is some algorithm in Matlab that calculates freq response from the ZPK directly without having to calculate polynomial coefficients.
Issues I encountered with foton.py:
- foton.py needs to strip the 0*j for real roots when parsing a string for foton
- There was a bug in the implementation, which was causing bogus errors
- I fixed this, and ported all my bug fixes to the main foton.py, attached here.
- foton accepts all the zeroes, but doesn't like the list of poles
- Unless I cut some poles to avoid this I get the following errors coming up due to sort_roots fuction (in IIRFilter/iirutil.cc) returning false to function s2z(in IIRFilter/iirutil.cc), which returns false to function zpk (in IIRFilter/IIRdesign.cc):
- poles must come in complex conjugates pairs
- Complex conjugates and poles must be in the left half plane
- Error adding ZPK
- I am required to cut out a couple of poles from the list if I want to function to be importable, poles with a positive real component make the TF unstable, so this error is understandable
- After manipulating the input list of poles, it accepts the poles as long as the imaginary values are not > +/- 51000. Somehow the code just rejects everything bigger for no reason that I can find in the code base.
- I multiply all Z and P by 0.1, and K by 0.01 (checked with Matlab, the TF is the same). (multiplying Z by 0.1 wasn't actually necsesary)
- Now this passes error checks ... but I get an error when attempting to write out the file:
- Invalid number of SOSs 203
- The SOS doesn't write out. Error arises in write function (of filterwiz/FilterFile.cc)
- Checks against on variable "kMaxFilterSOS" (found in filterwiz/FilterModule.hh)
- "kMaxFilterSOS = 10"
In summary two issues:
- I cannot produce frequency response plots in python to check against, but I can in Matlab.
- Python zpk handling functions all attempt to calculate polynomial coefficients, and that fails
- I cannot just import the zpk into foton.
- It produces more SOS than are allowed. This limitation maybe can to be lifted. O3b susmodels will need ~260
- foton flat out rejects zpk with poles in the right half plane - somehow matlab handles this fine, at least for plotting
- foton rejects zpks that have coefficients that are too large- but numbers can be scaled down in advance. I don't know where this limitation arises from
I did the same changes as I made in Python through Matlab, to see how different the TF looks when I remove the positive poles, and it is definitely not the same thing.
For the time being, one still needs to use quack to import the susmodels.