Frequency Response Function (FRF)

Created on Fri Mar 4 13:04:39 2022

@author: Daniel Kreuter

class softsensor.linear_methods.tf(window_size=512, fs=1024, hop=256, spectrum_type='spectrum')[source]

linear methods based on FFT and short term FFT Calculate the linear MiMo Transferfunction similar to Matlab tfestimate: https://uk.mathworks.com/help/signal/ref/tfestimate.html#bufqg8e

Parameters:
  • NFFT (int) – Length of the fft. The default ist 512.

  • fs (int) – sample frequency. The default ist 1024.

  • no_overlap (int) – Points overlapping. If None, than it is defined by no_overlap = np.fix(0.67 * NFFT) The default is None.

  • spectrum_type (str:) – ‘spectrum’ or ‘psd’. The default is ‘spectrum’.

Return type:

None.

Example

Computing the linear transfer function of a linear system with white noise excitation

>>> import softsensor.data_gen as dg
>>> import softsensor.linear_methods as lm
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> time = np.linspace(0, 100, 1000)
>>> params = {'D': 0.05, 'c_nlin': 0}
>>> F = dg.white_noise(time)
>>> df = dg.get_academic_data(time, Model='Duffing', F=F, params=params)
>>> model = lm.tf(NFFT=512, fs=fs, no_overlap=256)
>>> model.fit([df], ['F(t)'], ['x'])
>>> output = model.prediction(df, ['x'])
>>> plt.plot(df.index, df['x'], label='original')
>>> plt.plot(df.index, output, label='prediciton')
C:/Users/wet2rng/Desktop/Coding/SoftSensor/doc/img/lienar_tf.png
fit(df_list, inp_sens, out_sens)[source]

Fit linear TF to list of dfs by taking the mean transfer function

Parameters:
  • df_list (list of pd.DataFrame) – list of training Files.

  • inp_sens (list of str) – input sensors.

  • out_sens (list of str) – output sensors.

Return type:

None.

isfft(Zxx, columns=None, ampl_dist=None, boundary=True)[source]

Computes the inverse Fourier transformation

Parameters:
  • Zxx (Array,) – Fourier transformed signal.

  • columns (list of col names, optional) – Column names of the output df. The default is None.

  • ampl_dist (None, str, optional) – if STFT is a PSD, you can define the amplitude distribution with a Raleigh or mixed distribution. Options are None, ‘rayleigh’ or ‘mixed’. The default is None.

Returns:

TS_IFFT – DESCRIPTION.

Return type:

TYPE

prediction(test_df, columns=None, boundary=True)[source]

Predict test_df

Parameters:
  • test_df (pd.DataFrame) – dtaFrame for the precition, needs columns that have the same name as in fit.

  • columns (list of str, optional) – names for the prediction. The default is None.

Returns:

ts_pred – returns dataframe with linear_TF prediction as column.

Return type:

pd.DataFrame

sfft(ts)[source]

computes the short term fast Fourier transformation (stft) for each input column of the DataFrame

Parameters:

ts (pd.DataFrame) – pandas data frame.

Returns:

STFT – The Fourier transformed signal.

Return type:

array

tf_mimo(inp_df, out_df)[source]

ToDo: replace with scipy.signal.csd Calculate the linear MiMo Transferfunction similar to Matlab tfestimate: https://uk.mathworks.com/help/signal/ref/tfestimate.html#bufqg8e

Parameters:
  • inp_df (pandas DataFrame) – input x(t) (index is time stamp),

  • out_df (pandas DataFrame) – output y(t) (index is time stamp),

Returns:

  • tf (numpy array) –

    transfer function of shape (freq steps,no of out signals,

    no of input signal), complex

  • f (numpy array)

  • corresponding frequency array