chipmuenk / pyfda

Python Filter Design Analysis Tool
http://chipmuenk.github.io/
MIT License
643 stars 94 forks source link

Entering complex coefficients crashes pyfda #212

Closed chipmuenk closed 11 months ago

chipmuenk commented 2 years ago

This can be reproduced by selecting a FIR filter in the coefficient tab, clearing the coefficients and entering the coefficients '1' and '1j' and saving.

d:\daten\design\python\git\pyfda\pyfda\input_widgets\input_coeffs.py:254: ComplexWarning: Casting complex values to real discards the imaginary part
  self.parent.ba[0] = self.parent.ba[0].astype(complex)
d:\daten\design\python\git\pyfda\pyfda\input_widgets\input_coeffs.py:255: ComplexWarning: Casting complex values to real discards the imaginary part
  self.parent.ba[1] = self.parent.ba[1].astype(complex)
Traceback (most recent call last):
  File "d:\daten\design\python\git\pyfda\pyfda\input_widgets\input_coeffs.py", line 256, in setModelData
    self.parent.ba[index.column()][index.row()] = data  # store in self.ba
TypeError: can't convert complex to float

Creating complex coefficients by deleting a pole or zero in the P/Z editor, does not cause a crash. Editing the complex coefficients created this way also works without problems.

jeanibarz commented 2 years ago

I'm looking at this problem. Just for information, as of today, I've been able to reproduce the bug into the branch "file_io", but not on branch "master".

jeanibarz commented 2 years ago

When a complex pole/zero was entered, the array ba was converted into complex type if necessary, but not the ba_q array. Trying to assign the complex value to float type array ba_q was causing the crash, hence I added a line to convert ba_q into complex type before assignment, similarly to what was done with the ba array.