Commit f7099bb3 authored by Matthieu Cattin's avatar Matthieu Cattin

Plot frequency response in dB.

parent b8629c15
...@@ -17,53 +17,50 @@ from ptsexcept import * ...@@ -17,53 +17,50 @@ from ptsexcept import *
""" """
test10: Plot frequency response summary data from test09 log file test10: Plot frequency response summary data from test09_freq_resp.txt file
Note: Requires test00.py to run first to load the firmware and Note: Requires test00.py to run first to load the firmware and
test09.py to generate the log file. test09.py to generate the file.
""" """
def show_result_graph(points, ch_att):
pt = array(points)
freq = pt[:,0]
a_min = pt[:,1] - pt[:,2]
a_max = pt[:,1] + pt[:,2]
cutoff = [-3] * len(points)
semilogx(freq, ch_att[0], 'b', label='Channel 1')
semilogx(freq, ch_att[1], 'g', label='Channel 2')
semilogx(freq, ch_att[2], 'm', label='Channel 3')
semilogx(freq, ch_att[3], 'c', label='Channel 4')
semilogx(freq, a_min, 'r:')
semilogx(freq, a_max, 'r:')
semilogx(freq, cutoff, 'r', label='-3dB')
grid(color='k', linestyle='--', linewidth=1)
legend(loc='upper left')
show()
return 0
def main (default_directory='.'): def main (default_directory='.'):
# open test09 log file in read mode # Open test09_freq_resp.txt file in read mode
file_name = raw_input('Enter a file name (default=log_test09.txt):') file_name = "test09_freq_resp.txt"
if file_name == "": f = open(file_name, 'r+')
file_name = "log_test09.txt"
file = open(file_name, 'r+')
# Read file # Read file
points = [] points = []
ch_diff = [] ch_att = [[],[],[],[]]
for line in file: for line in f:
#print('Line:%s')%line
freq,expect_val,tol,ch1,ch2,ch3,ch4 = line.split(',') freq,expect_val,tol,ch1,ch2,ch3,ch4 = line.split(',')
#print('%s %s %s %s %s %s %s')%(freq,expect_val,tol,ch1,ch2,ch3,ch4) points.append([float(freq),float(expect_val),float(tol)])
#print('%3.3f %d %d %d %d %d %d')%(float(freq),int(expect_val),int(tol),int(ch1),int(ch2),int(ch3),int(ch4)) ch_att[0].append(float(ch1))
points.append([float(freq),int(expect_val),int(tol)]) ch_att[1].append(float(ch2))
ch_diff.append(int(ch1)) ch_att[2].append(float(ch3))
ch_diff.append(int(ch2)) ch_att[3].append(float(ch4))
ch_diff.append(int(ch3)) f.close()
ch_diff.append(int(ch4))
#print points # Plot results
#print('##########') show_result_graph(points, ch_att)
#print ch_diff
#sys.exit()
# The following code is to show a graph of the test results
# !! Don't forget to import numpy and pylab !!
pt = array(points)
freq = pt[:,0]
a_min = pt[:,1] - pt[:,2]
a_max = pt[:,1] + pt[:,2]
semilogx(freq, ch_diff[0::4], 'b', label='Channel 1')
semilogx(freq, ch_diff[1::4], 'g', label='Channel 2')
semilogx(freq, ch_diff[2::4], 'r', label='Channel 3')
semilogx(freq, ch_diff[3::4], 'c', label='Channel 4')
semilogx(freq, a_min, 'r:', label='Lower limit')
semilogx(freq, a_max, 'r:', label='Upper limit')
legend()
show()
if __name__ == '__main__' : if __name__ == '__main__' :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment