Bode plot from time series experiment data - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Bode plot from time series experiment data (/thread-27718.html) |
Bode plot from time series experiment data - discus - Jun-18-2020 Hello everyone!^^ I am new to python coding. By the way, please give me a way to draw a bode plot simply without calculating the gain and phase by fft processing each with 2 time series experiment data! Please introduce the code that can be easily processed through functions such as Scipy... Thank you in advance!! RE: Bode plot from time series experiment data - Marbelous - Jun-18-2020 Hello discus! ^^ Welcome to python-forum. By the way, please show us what you have tried to code this yourself! We like to help people learn but generally don't just write code for them! Please check into the bode function built into Scipy: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.bode.html Also take a look at how to use Matplotlib: https://matplotlib.org/ Thank You!! RE: Bode plot from time series experiment data - pyzyx3qwerty - Jun-18-2020 Welcome to the forum! I hope you have an exciting journey in this forum - but first, you need to post your code for us to help you with the error/output. Also, remember to use proper tags while coding - see BBCode to know more RE: Bode plot from time series experiment data - discus - Jun-19-2020 In the past, I did fft-convert two time series data of'x0(time):x1' and'x0(time):x2' with FORTRAN code. Using these frequency domain spectrum, I calculated the gain and phase of the 'x2 output' for the 'x1 input' and drew a bode plot. There are many Bode Plot related functions in SciPy, but I would like to know how to obtain the gain and phase of Bode Plot simply by inputting two time series data obtained from experiments like me!! I would like to know how to solve it by simply using functions like SciPY at a time. I wait for your advice... Attach my Python code and input data file. import matplotlib.pyplot as plt import numpy as np import math import sys import xlwt from scipy import signal signal_id = [] x = [[0 for col in range(5)] for row in range(10000)] grav = 9806.65 rtod = 180 / np.pi dtor = np.pi / 180 def FileRead(f): i = 0 while True: line = f.readline() if not line: f.close() break if i == 0: signal_id = line.split() sg_cnt = len(signal_id) else: x[i-1][:] = map(float,line.split()) i = i + 1 ndata = i - 1 print('$ ndata, sg_cnt : ',ndata,sg_cnt) print('$ signal_id : ',signal_id) return ndata, sg_cnt def impulse_response(ndata, x, filename): print('$ impulse_response') for i in range(0,ndata): # Check test data if(np.mod(i,100) == 0): print('x :',x[i][0],x[i][1],x[i][2],x[i][3],x[i][4]) # Please insert the calculation porcess to obtain gain and phase of Bode plot... # Input Time Signal : x[:][0],x[:][1] # Output Time Signal : x[:][0],x[:][2] print(' ') print(' ') print(' ') print(' *** Please help me !! ^^ ') print(' ') # # In the past, I did fft-convert two time series data of'x0(time):x1' and'x0(time):x2' with FORTRAN code. # Using these frequency domain spectrum, I calculated the gain and phase of the 'x2 output' for the 'x1 input' and drew a bode plot. # There are many Bode Plot related functions in SciPy, # but I would like to know how to obtain the gain and phase of Bode Plot simply # by inputting two time series data obtained from experiments like me!! #.................................................................... # # scipy.signal.bode # scipy.signal.bode(system, w=None, n=100)[source] # Calculate Bode magnitude and phase data of a continuous-time system. # Parameters # systeman instance of the LTI class or a tuple describing the system. # The following gives the number of elements in the tuple and the interpretation: # 1 (instance of lti) # 2 (num, den) # 3 (zeros, poles, gain) # 4 (A, B, C, D) # warray_like, optional # Array of frequencies (in rad/s). Magnitude and phase data is calculated for every value in this array. If not given a reasonable set will be calculated. # nint, optional # Number of frequency points to compute if w is not given. The n frequencies are logarithmically spaced in an interval chosen to include the influence of the poles and zeros of the system. # Returns # w1D ndarray # Frequency array [rad/s] # mag1D ndarray # Magnitude array [dB] # phase1D ndarray # Phase array [deg] #------------------------------------------------------------------- while True: print(' ') print('=====================================') print('$ Input File Name(*.txt) ?') print('=====================================') filename = input() if ("_imp"in filename): f = open(filename+".txt", 'r'); ndata, sg_cnt = FileRead(f) impulse_response(ndata, x, filename) else: print('*** Normal End of Job !') sys.exit() RE: Bode plot from time series experiment data - discus - Jun-20-2020 I finally found what I was looking for... I struggled for a few days with something simpler than I thought. https://www.youtube.com/watch?v=Syg1q3JO978&t=1187s |