/usr/share/expeyes/eyes/freq-response.py is in expeyes 3.4.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | '''
expEYES program
Author : Ajith Kumar B.P, bpajith@gmail.com
License : GNU GPL version 3
'''
from Tkinter import *
import expeyes.eyes as eyes, expeyes.eyeplot as eyeplot, expeyes.eyemath as eyemath, time, sys, numpy
import gettext
gettext.bindtextdomain("expeyes")
gettext.textdomain('expeyes')
_ = gettext.gettext
TIMER = 100
WIDTH = 600 # width of drawing canvas
HEIGHT = 400 # height
NP = 30
fmin = 2500.0
freq = fmin
fmax = 5000.0
vpeak = 0 # Assume as 0
fpeak = fmin
history = [] # Data store
trial = 0 # trial number
data = [ [], [] ] # Current & Voltage
index = 0
running = False
def start():
global running, NP, freq, fmin, data, index
running = True
data = [ [], [] ]
index = 0
freq = fmin
ph.set_upv(5)
ph.set_sqr1(fmin)
root.after(10,update)
def update(): # Called periodically by the Tk toolkit
global running, NP, freq, fmax, fpeak, vpeak, history, data, index, trial
if running == False:
return
fr = ph.set_sqr1(freq)
freq += 20
t,v = ph.capture(0,400,20)
rmsv = ph.rms(v)
data[0].append(fr)
data[1].append(rmsv)
if rmsv > vpeak:
vpeak = rmsv
fpeak = fr
if fr > fmax:
running = False
history.append(data)
trial += 1
g.delete_lines()
for k in range(len(history)):
g.line(history[k][0], history[k][1], k)
vmax = max(data[1])
R.config(text=_('Fo = %5.0f Hz') %fpeak)
ph.set_sqr1(0)
return
if index > 1: # Draw the line
g.delete_lines()
g.line(data[0], data[1], trial)
index += 1
root.after(TIMER, update)
def xmgrace(): # Send the data to Xmgrace
global history
try:
import pygrace
except:
return
pg = pygrace.grace()
for dat in history:
pg.plot(dat[0],dat[1])
pg.hold(1) # Do not erase the old data
pg.xlabel(_('Frequency'))
pg.ylabel(_('Amplitude'))
pg.title(_('Frequency response curve'))
def save():
global history, running
if running == True:
return
s = e1.get()
if s == '':
return
f = open(s, 'w')
for dat in history:
for k in range(len(dat[0])):
f.write('%5.3f %5.3f\n'%(dat[0][k], dat[1][k]))
f.write('\n')
f.close()
msg.config(text = _('Data saved to file ')+s)
def clear():
global history, trial, running
if running == True:
return
g.delete_lines()
history = []
trial = 0
def quit():
ph.set_sqr1(0)
sys.exit()
ph = eyes.open()
ph.loadall_calib()
root = Tk()
Canvas(root, width = WIDTH, height = 5).pack(side=TOP) # Some space at the top
g = eyeplot.graph(root, width=WIDTH, height=HEIGHT) # make plot objects using draw.disp
g.setWorld(fmin, 0, fmax, 5.0,_('Freq'),_('Amp'))
cf = Frame(root, width = WIDTH, height = 10)
cf.pack(side=TOP, fill = BOTH, expand = 1)
b1 = Button(cf, text = _('START'), command = start)
b1.pack(side = LEFT, anchor = N)
b3 = Button(cf, text = _('SAVE to'), command = save)
b3.pack(side = LEFT, anchor = N)
filename = StringVar()
e1 =Entry(cf, width=15, bg = 'white', textvariable = filename)
filename.set('freq-response.dat')
e1.pack(side = LEFT)
R = Label(cf,text=_('Fmax = '))
R.pack(side=LEFT)
b5 = Button(cf, text = _('QUIT'), command = quit)
b5.pack(side = RIGHT, anchor = N)
b4 = Button(cf, text = _('CLEAR'), command = clear)
b4.pack(side = RIGHT, anchor = N)
b5 = Button(cf, text = _('Grace'), command = xmgrace)
b5.pack(side = RIGHT, anchor = N)
mf = Frame(root, width = WIDTH, height = 10)
mf.pack(side=TOP, fill = BOTH, expand = 1)
msg = Label(mf,text=_('Connect Piezo from SQR1 to GND. Microphone to 16,15 & 31. Wire from 13 to 26'), fg = 'blue')
msg.pack(side=LEFT)
eyeplot.pop_image('pics/freq-resp.png', _('Frequency Response Curve'))
root.title(_('Audio Frequency response Curve'))
root.mainloop()
|