-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathultra.py
More file actions
203 lines (159 loc) · 4.81 KB
/
ultra.py
File metadata and controls
203 lines (159 loc) · 4.81 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def nextpow2(n):
from numpy import log2, ceil
N=2**int(ceil(log2(n)))
return N
def GetData(navg=2,nloc=1,chnum=1):
import visa
from numpy import linspace,array,mean
rm=visa.ResourceManager()
s=rm.open_resource('USB0::0x0957::0x1797::MY52160825::INSTR')
while (chnum!=1) and (chnum!=2):
chnum=input('Input a valid channel number (1 or 2) :')
s.write('*CLS')
s.write(':stop')
s.write(':waveform:format ascii')
s.write(':waveform:source channel'+str(int(chnum)))
s.write(':waveform:points:mode maximum')
X=[]
T=[]
for i in range(nloc):
s.write(':acquire:type normal')
s.write(':run')
print('Location '+str(i+1))
raw_input('Press Any Key to Collect Signal')
s.write(':acquire:type average')
s.write(':acquire:count '+str(nextpow2(navg)))
s.write(':digitize channel'+str(int(chnum)))
xst=s.query(':waveform:data?')
N=float(s.query(':waveform:points?'))
t0=float(s.query(':WAVeform:XOrigin?'))
dt=float(s.query(':waveform:xincrement?'))
t=linspace(t0,dt*N+t0,N)
xst=s.query(':waveform:data?')
xst=xst[10::].split(',')
x=[float(xx) for xx in xst]
x=array(x)
x=x-mean(x)
T.append(t)
X.append(x)
s.write(':acquire:type normal')
s.write(':run')
s.clear()
return T,X
def GetWavespeedAttenuation(t,x,d):
from numpy import log
from scipy.signal import hilbert
from spr import pkfind
c=[]
alpha=[]
for i in range(len(d)):
tp,xp=pkfind(t[i],abs(hilbert(x[i])),2)
c.append(2*1e-6*d[i]/(tp[1]-tp[0]))
alpha.append(-log(xp[1]/xp[0])/(2*d[i]))
return c,alpha
def SignalIndex(x,indmax,sigma,thresh=1.):
indleft=indmax
indright=indmax
SNR=x[indmax]/sigma
while SNR>thresh:
indleft -=1
SNR=x[indleft]/sigma
SNR=x[indmax]/sigma
while SNR>thresh:
indright +=1
SNR=x[indright]/sigma
return indleft,indright
def GumbleFit():
# def fsweep(frange,navg,flname,ctype,ch=1,delaytime=0.5,overwrite=False,cycles=10,vamp=5.0):
# import visa
# from numpy import linspace,array,floor
# import os
# from time import sleep
#
# while (navg<2) or (navg>65536):
# navg=input('Input a number of averages between 2 and 65536 :')
#
# f = 1e6*linspace(frange[0],frange[1],floor((frange[1]-frange[0])/frange[2])+1)
#
# s.write('*CLS')
# s.write(':wgen:function sinusoid')
# s.write(':wgen:voltage:high '+str(vamp/2))
# s.write(':wgen:voltage:low '+str(-vamp/2))
# s.write(':acquire:type average')
# s.write(':acquire:count '+str(nextpow2(navg)))
# s.write(':wgen:output 1')
# s.write(':trigger:source wgen')
#
# s.write(':waveform:source channel'+str(ch))
# s.write(':timebase:vernier 1')
#
# for ff in f:
# print(str(ff*1e-6)+' MHz')
# s.write(':wgen:frequency '+str(ff))
# s.write(':timebase:scale '+str(float(cycles/ff/10)))
# sleep(delaytime)
# s.write(':digitize channel'+str(ch))
# X=float(s.query(':measure:vrms? channel'+str(ch)))
# print(str(X))
# with open(flname, 'ab') as fl:
# fl.write(str(ff*1e-6)+'\t'+str(X/vamp)+'\n')
#
# with open(flname, 'ab') as fl:
# fl.write(str(ff*1e-6)+'\t'+str(X)+'\n')
#
#
# s.write(':wgen:output 0')
# class Sample:
#
# def __init__(self,h,temp,freq):
#
# self.CentreFrequency=freq
# self.Thickness=h
# self.CureTemperature=temp
#
# def GetSignal(self,navg):
#
# t,x=getdata(navg,len(self.Thickness))
# self.Time=t
# self.Data=x
#
# def GetWavespeedDamping(self):
#
# from numpy import mean,std,array
#
# c,alpha=get_c_alpha(self.Time,self.Data,self.Thickness)
#
#
# self.Wavespeed=c
# self.Damping=alpha
#
# c=array(c)
# alpha=array(alpha)
#
# self.AverageWavespeed=mean(c)
# self.AverageDamping=mean(alpha)
# self.WavespeedDeviation=100*std(c)/mean(c)
# self.DampingDeviation=100*std(alpha)/mean(alpha)
#
# def Save(self,filename,writemode='append',pth='/Users/jlesage/Dropbox/ShawCorr/'):
#
# import pickle,os
#
# fl=pth+filename+'.p'
#
# if (os.path.isfile(fl))&(writemode is 'append'):
#
# s=pickle.load(open(fl,'rb'))
# s.append(self)
# pickle.dump(s,open(fl,'wb'))
#
#
# else:
#
# s=[]
# s.append(self)
# pickle.dump(s,open(fl,'wb'))
#
#
#
#