Python Forum
Bode plot from time series experiment data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bode plot from time series experiment data
#1
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!!
Reply
#2
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/....bode.html
Also take a look at how to use Matplotlib: https://matplotlib.org/

Thank You!!
"So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!" - Tim the Enchanter
Reply
#3
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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#4
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()
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Date Time Series Help...Please spra8560 2 314 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Likert survey data plot error Andrzej_Andrzej 6 1,308 Jul-16-2023, 10:11 PM
Last Post: deanhystad
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 802 May-29-2023, 02:42 PM
Last Post: Nietzsche
  Print names in x-axis of a time-series values hobbyist 4 1,178 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  first time use plot - I get empty graph korenron 6 1,969 Feb-04-2023, 02:14 PM
Last Post: deanhystad
  Create simple live plot of stock data dram 2 2,859 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 897 Jan-21-2023, 05:01 PM
Last Post: nicholas
  Time series JasminQuinn 0 1,005 Apr-22-2022, 10:33 PM
Last Post: JasminQuinn
  Real time data satyanarayana 3 20,364 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  How to read rainfall time series and insert missing data points MadsM 4 2,125 Jan-06-2022, 10:39 AM
Last Post: amdi40

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020