Demo entry 6350162



Submitted by anonymous on Mar 07, 2017 at 08:08
Language: Python. Code size: 1.1 kB.

#Guy Everett
#Bioen 336
#HW 5

#Importing libraries
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

# User input for numerator of transfer function 
num = float(raw_input("numerator:"))
# Coefficients in denominator of transfer function 
# High order to low order, eg 1*s^2 + 0.1*s + 1 
a = float(raw_input("S^3 coefficient:"))
b = float(raw_input("S^2 coefficient:"))
c = float(raw_input("S^1 coefficient:"))
d = float(raw_input("S^0 coefficient:"))
den = [a, b, c, d]
#User input for frequency range 
freq_start = float(raw_input("Starting Frequency:"))
freq_end = float(raw_input("Ending Frequency:"))
freq_step = float(raw_input("Frequency Range Stepsize:"))
freq_range = np.arange(freq_start, freq_end, freq_step).tolist()
#Creates the linear, time-invariant, system
s1 = signal.lti(num, den)    
w, mag, phase = signal.bode(s1, freq_range) 

plt.semilogx (w, mag, color="green", linewidth="1") 
plt.title ("Magnitude Plot")
plt.xlabel ("Frequency (Hz)") 
plt.ylabel ("Magnitude (dB)")

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).