```python
import sympy as sp
from sympy import poly
import numpy as np
import math
import matplotlib.pyplot as plt
class TransferFunctionModel(object):
    #TransferFunction Model, num and den is coefficent
    def __init__(self,num,den,tau = 0):
        self.num = num
        self.den = den
        self.tau = tau
        pass
    
    def freqres(self, w, unwarp = False):
        
        b = self.num
        a = self.den
        tau = self.tau
        s = 1j * w
        h = np.polyval(b, s) * np.exp(-tau * s) / np.polyval(a, s)
        print(np.absolute(h))
        h = np.complex64(h)
        amp = 20 * np.log10(np.absolute(h))
        pha = None
        if unwarp:
            pha = np.unwrap(np.arctan2(h.imag, h.real)) * 180 / math.pi
        else:
            pha = np.arctan2(h.imag, h.real) * 180 / math.pi
        return amp, pha
    
    
    def plot(self, freq = None):
        if freq is None:
            freq = np.linspace(1.0,10,10)
        print(freq)
        amp,pha = self.freqres(freq,True)
        plt.semilogx(freq,amp,label="Amp")
        plt.semilogx(freq,pha,label="Pha")

    

class TransferFunctionParamModel(object):
    #A TransferFunction with unknown parameters
    
    def __init__(self,num,den,tau = 0):
        self.num = num
        self.den = den
        self.tau = tau
        self.s = sp.symbols('s')
    
    def transfer_function_by_dict(self, sym_dict):
        s = self.s
        num_formula =  self.num.subs(sym_dict)
        num = poly(num_formula,s).all_coeffs()

        den_formula =  self.den.subs(sym_dict)
        den = poly(den_formula,s).all_coeffs()
        
        return TransferFunctionModel(num,den,self.tau)
    
    def get_unknown_param_list(self):
        syms = self.num.atoms(sp.Symbol) 
        syms.update(self.den.atoms(sp.Symbol))
        syms.remove(self.s)
        return syms
```


```python
s,a,b,c = sp.symbols('s a b c')
num = c*s+0
den = a*s**2 + b*s

tfparam = TransferFunctionParamModel(num,den)

tf = tfparam.transfer_function_by_dict({
    a : 2,
    b:  3,
    c : 5
})
tf.__dict__
tf.plot()
```


```python
tfparam.get_unknown_param_list()
```




    {a, b, c}




```python

```

8f5e310802fc163900aa024dab00fb94518abdfd
ipynb
Jupyter Notebook
AircraftIden/Untitled.ipynb
xuhao1/pyAircraftIden
b66efd377328264824250d8f53ca9a5d9321a04f
MIT
2020-06-12T06:01:54.000Z
2022-02-21T14:49:09.000Z
AircraftIden/Untitled.ipynb
xuhao1/pyAircraftIden
b66efd377328264824250d8f53ca9a5d9321a04f
MIT
2022-01-15T15:10:19.000Z
2022-01-15T15:10:19.000Z
AircraftIden/Untitled.ipynb
xuhao1/pyAircraftIden
b66efd377328264824250d8f53ca9a5d9321a04f
MIT
2020-06-27T19:13:49.000Z
2020-06-27T19:13:49.000Z
Qwen/Qwen-72B
1. YES
2. YES