• Overview
    • English (Global)
    • 日本語 (Japan)
  • Control Theory
  • Python
  • TwinCAT
  • Profile
  • Training
    • English (Global)
    • 日本語 (Japan)
  • English (Global)
  • 日本語 (Japan)
  1. Python
  2. Python library: pylib-sakata
  3. Function manual of fft
  • Python

    • Environment Setup
      • How to create a Python virtual environment
      • Python IDE Installation Guide

    • Python library: pylib-sakata
      • Setup of pylib-sakata
      • Function manual of ctrl
      • Function manual of fft
      • Function manual of meas
      • Function manual of traj
      • Function manual of plot
      • Function manual of init

    • Simulation
      • Precise Time-Domain Simulation of High-Order LTI Systems

On this page

  • pylib_sakata.fft
    • FreqResp
    • fft
    • fft_ave
    • tfestimate
    • frdresize
    • frdsim
  1. Python
  2. Python library: pylib-sakata
  3. Function manual of fft

Function manual of fft

pylib_sakata.fft

FreqResp

class pylib_sakata.fft.FreqResp(freq, resp, dt=0)

  • Parameters:
    • freq: 1-D array frequency data [Hz]
    • resp: 1-D array frequency response data [complex data]
    • dt: sampling time (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.

Examples Refer examples of sys2frd.

Methods - __neg__() Negate a FRD.

  • __add__(other) Add two FRDs (parallel connection).

  • __radd__(other) Right add two FRDs (parallel connection).

  • __sub__(other) Subtract two FRDs (parallel connection).

  • __rsub__(other) Right subtract two FRDs (parallel connection).

  • __mul__(other) Multiply two FRDs (serial connection).

  • __rmul__(other) Right multiply two FRDs (serial connection).

  • __truediv__(other) Divide two FRDs (serial connection).

  • __rtruediv__(other) Right divide two FRDs (serial connection).

  • __pow__(other) A FRD to the power of x.

  • __matmul__(other) Multiply two MIMO FRDs.

  • __mod__(other) Divide two MIMO FRDs.

  • addeye() Add identify matrix to a MIMO FRD.

  • inv() Inverse matrix of a MIMO FRD.

  • pinv() Moore-Penrose pseudo-inverse matrix of a MIMO FRD.

  • rga() Relative gain array of a MIMO FRD.

  • det() Determinant of a MIMO FRD.

  • eig() Eigen value of a MIMO FRD.

  • svd() Singular value of a MIMO FRD.

fft

pylib_sakata.fft.fft(data, dt)

This function is for calculating FFT from 1-D array data.

  • Parameters:
    • data: 1-D array time response data
    • dt: sampling time of the time response data
  • Returns:
    • freq_data: 1-D array frequency data [Hz]
    • fft_data: 1-D array FFT data

Examples

import numpy as np
>>> dt = 0.001
>>> t = np.linspace(0.0, 10., int(10./dt))
>>> x = np.sin(2*np.pi*10.0*t) + np.sin(2*np.pi*50.0*t)
>>> fft.fft(x, dt)
(array([0.00000000e+00, 1.00010001e-01, 2.00020002e-01, ...,
       9.99799980e+02, 9.99899990e+02, 1.00000000e+03]), array([3.93463040e-17, 2.39600781e-06, 4.79322523e-06, ...,
       7.19286425e-06, 4.79322523e-06, 2.39600781e-06]))

fft_ave

pylib_sakata.fft.fft_ave(data, dt, windivnum=4, overlap=0.5)

This function is for calculating averaged FFT from 1-D array data.

  • Parameters:
    • data: 1-D array time response data
    • dt: sampling time of the time response data
    • windivnum: number of windows to divide the time response data
    • overlap: overlap ratio divided time response data (0 <= overlap < 1)
  • Returns:
    • freq_data: 1-D array frequency data [Hz]
    • fft_data: 1-D array FFT data

Examples

import numpy as np
>>> dt = 0.001
>>> t = np.linspace(0.0, 10., int(10./dt))
>>> x = np.sin(2*np.pi*10.0*t) + np.sin(2*np.pi*50.0*t)
>>> fft.fft_ave(x, dt, 4, 0.5)
(array([0.00000000e+00, 4.88519785e-01, 9.77039570e-01, ...,
       9.99022960e+02, 9.99511480e+02, 1.00000000e+03]), array([5.33388114e-05, 5.46444944e-05, 5.85999322e-05, ...,
       6.53498409e-05, 5.85999322e-05, 5.46444944e-05]))

tfestimate

pylib_sakata.fft.tfestimate(x, y, freq, dt, windivnum=4, overlap=0.5)

This function is for system identification from input and output time response data.

  • Parameters:
    • x: 1-D array time response data of input
    • y: 1-D array time response data of output
    • freq: 1-D array frequency data [Hz]
    • dt: sampling time of the time response data
    • windivnum: number of windows to divide the time response data
    • overlap: overlap ratio divided time response data (0 <= overlap < 1)
  • Returns:
    • freqresp: instance of FreqResp class
    • coh: 1-D array coherence data

Examples

>>> import numpy as np
>>> from scipy import signal
>>> from control import matlab
>>> P_tf = ctrl.tf([1.], [1., 2., 0.])
>>> C_tf = ctrl.tf([2., 4., 1.], [1., 2., 0.])
>>> dt = 0.001
>>> t = np.linspace(0.0, 10., int(10./dt))
>>> d = signal.chirp(t, f0=0.1, f1=500., t1=50., method='logarithmic', phi=-90.)
>>> u, tout, xout = matlab.lsim(ctrl.feedback(P_tf, C_tf), d, t)
>>> y, tout, xout = matlab.lsim(ctrl.feedback(P_tf, C_tf, 'SP'), d, t)
The common pole-zeros of the zpk model have been deleted.
>>> freq = np.logspace(np.log10(1.), np.log10(500.), 10000, base=10)
>>> fft.tfestimate(u, y, freq, dt)
(array([-0.11586071-1.49076948e-01j, -0.11590257-1.49078279e-01j,
       -0.11594446-1.49079611e-01j, ..., -0.13155661-1.45847229e-01j,
       -0.14201211-1.03211830e-01j, -0.15745492-1.88460358e-14j]), array([0.77271576, 0.77244166, 0.7721674 , ..., 0.23080322, 0.32843388,
       0.43848208]))

frdresize

pylib_sakata.fft.frdresize(freqresp, freq)

This function is for resizing a frequency response data.

  • Parameters:
    • freqresp: instance of FreqResp class
    • freq: new 1-D array frequency data [Hz] for resize
  • Returns:
    • freqresp: resized instance of FreqResp class based on new frequency data array

Examples

>>> import numpy as np
>>> freq = np.logspace(np.log10(1.), np.log10(1000.), 100, base=10)
>>> Sys_tf = ctrl.tf([1., 2.], [3., 4., 5.])
>>> freqresp = ctrl.sys2frd(Sys_tf, freq)
>>> freq_resize = np.logspace(np.log10(1.), np.log10(1000.), 10000, base=10)
>>> fft.frdresize(freqresp, freq_resize)

freq = array([   1.            1.00069108    1.00138264 ...  998.61926487  999.30939397
 1000.        ])
resp = array([-5.10821217e-03-5.65218353e-02j -5.10244172e-03-5.64813436e-02j
 -5.09666728e-03-5.64408239e-02j ... -5.64622394e-09-5.31301950e-05j
 -5.63759203e-09-5.30909366e-05j -5.62895416e-09-5.30516511e-05j])

frdsim

pylib_sakata.fft.frdsim(freqresp, x, dt)

This function is for simulation steady time response data when a time-domain data is input to a system written by frequency response data. \[y(t) = \text{ifft}(\text{FreqResp}(\omega)\circ\text{fft}(u(t)))\]

  • Parameters:
    • freqresp: instance of FreqResp class
    • x: 1-D array time response data of input
    • dt: sampling time of the time response data
  • Returns:
    • y: 1-D array time response data of output

Examples

>>> import numpy as np
>>> freq = np.logspace(np.log10(1.), np.log10(1000.), 100, base=10)
>>> Sys_tf = ctrl.tf([1., 2.], [3., 4., 5.])
>>> freqresp = ctrl.sys2frd(Sys_tf, freq)
>>> dt = 0.001
>>> t = np.arange(int(10./dt)) * dt
>>> x = np.sin(2*np.pi*10.0*t) + np.sin(2*np.pi*50.0*t)
>>> fft.frdsim(freqresp, x, dt)
array([-0.00636997, -0.00631177, -0.00613378, ..., -0.00582607,
       -0.00611703, -0.00630332])

© 2026 Koichi Sakata

Built with Quarto

  • Privacy Policy