Skip to content

Commit

Permalink
Fix density calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliovv committed Oct 31, 2021
1 parent 57b555c commit b555663
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 55 deletions.
40 changes: 20 additions & 20 deletions examples/test.ipynb

Large diffs are not rendered by default.

63 changes: 36 additions & 27 deletions examples/tfest_example.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
setuptools.setup(
name = 'tfest',
packages = ['tfest'],
version = '0.1.11',
version = '0.1.12',
license="""MIT""",
description = """Transfer function estimation based on frequency response.""",
long_description_content_type="text/markdown",
long_description=README,
author = 'Giulio Vaccari',
author_email = 'io@giuliovaccari.it',
url = 'https://github.com/giuliovv/tfest',
download_url = 'https://github.com/giuliovv/tfest/archive/refs/tags/v0.1.11-alpha.tar.gz',
download_url = 'https://github.com/giuliovv/tfest/archive/refs/tags/v0.1.12-alpha.tar.gz',
keywords = ['tfest', 'frequency', 'matlab'],
install_requires=[
'matplotlib',
Expand Down
Binary file modified tfest/__pycache__/tfest.cpython-36.pyc
Binary file not shown.
13 changes: 7 additions & 6 deletions tfest/tfest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,30 @@ def frequency_response(self, method="h1", time=None):
if time == None:
warnings.warn("Setting default time=1")
time = 1
dt = time/len(self.u)
if method == "fft":
u_f = fft(self.u)
y_f = fft(self.y)
u_no_zero = u_f[np.nonzero(u_f)]
y_no_zero = y_f[np.nonzero(u_f)]
frequency = fftfreq(u_f.size, d=time/len(self.u))[np.nonzero(u_f)]
frequency = fftfreq(u_f.size, d=dt)[np.nonzero(u_f)]
H = y_no_zero/u_no_zero
elif method == "h1":
# https://dsp.stackexchange.com/questions/71811/understanding-the-h1-and-h2-estimators
cross_sd, frequency = csd(self.y, self.u, Fs=time/len(self.u))
power_sd, _ = psd(self.u, Fs=time/len(self.u))
cross_sd, frequency = csd(self.u, self.y, Fs=1/dt, NFFT=len(self.u))
power_sd, _ = psd(self.u, Fs=1/dt, NFFT=len(self.u))
H = cross_sd/power_sd
elif method == "h2":
cross_sd, frequency = csd(self.u, self.y, Fs=time/len(self.u))
power_sd, _ = psd(self.y, Fs=time/len(self.u))
cross_sd, frequency = csd(self.y, self.u, Fs=1/dt, NFFT=len(self.u))
power_sd, _ = psd(self.y, Fs=1/dt, NFFT=len(self.u))
H = power_sd/cross_sd
else:
raise Exception("Unknown method")
self.frequency = frequency
self.H = H
return self.H, frequency

def estimate(self, nzeros, npoles, init_value=1, options={'xatol': 1e-2, 'disp': True}, method="density", time=1):
def estimate(self, nzeros, npoles, init_value=1, options={'xatol': 1e-3, 'disp': True}, method="h1", time=None):
"""
npoles: number of poles
nzeros: number of zeros
Expand Down

0 comments on commit b555663

Please sign in to comment.