Changeset 4195
- Timestamp:
- 06/18/07 16:24:56 (6 years ago)
- Location:
- experimental/AWG/trunk/AWG
- Files:
-
- 2 modified
-
AWG.py (modified) (2 diffs)
-
sources.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
experimental/AWG/trunk/AWG/AWG.py
r4194 r4195 19 19 self.parent = parent 20 20 21 def get_signal(self, signal_ type, file_name):21 def get_signal(self, signal_index, file_name): 22 22 #signal I want is hard-coded for now 23 self.signal_ type = signal_type23 self.signal_index = signal_index 24 24 self.signal_len = 8192 #length of packet 25 25 self.frequency = 5 #cycles per packet 26 rand_type = 'random'26 self.rand_type = 'random' 27 27 self.file_name = file_name 28 delimiter = ','28 self.delimiter = ',' 29 29 30 30 my_signal = sources.sources(self) #instance of signals class 31 32 self.signal_type = self.signal_type.lower() #makes comparison case insesitive 33 if self.signal_type == 'sine': 34 self.the_signal = my_signal.gen_sine(self.frequency, self.signal_len) 35 elif self.signal_type == 'cosine': 36 self.the_signal = my_signal.gen_cosine(self.frequency, self.signal_len) 37 elif self.signal_type == 'random': 38 self.the_signal = my_signal.gen_random_data(self.signal_len, rand_type) 39 elif self.signal_type == 'file': 40 self.the_signal = my_signal.read_file(self.file_name, delimiter) 41 elif self.signal_type == 'zeros': 42 self.the_signal = my_signal.gen_zeros(self.signal_len) 43 else: 44 print "signals other than sine,cosine, rand, zeros, and readfile are not supported yet in _get_signal" 31 self.the_signal = my_signal.gen_signal() 45 32 46 33 return self.the_signal … … 196 183 self.q_file_name = self.qFileNameEditor.GetLineText(0) 197 184 AWG_instance = AWG(self) 198 i_source_selected = self.iSourceChoice.GetS tringSelection()199 q_source_selected = self.qSourceChoice.GetS tringSelection()185 i_source_selected = self.iSourceChoice.GetSelection() 186 q_source_selected = self.qSourceChoice.GetSelection() 200 187 self.I = AWG_instance.get_signal(i_source_selected, self.i_file_name) 201 188 self.Q = AWG_instance.get_signal(q_source_selected, self.q_file_name) -
experimental/AWG/trunk/AWG/sources.py
r4194 r4195 8 8 self.parent = parent 9 9 self.available_sources = ['file', 'sine', 'cosine', 'random', 'zeros'] 10 #IMPORTANT: corresponding_methods must be in the same order as the available_sources 10 11 self.corresponding_methods = ['read_file','gen_sine', 'gen_cosine', 'gen_random_data', 'gen_zeros'] 11 12 … … 16 17 17 18 def gen_signal(self): 18 pass 19 eval_string = "self." + self.corresponding_methods[parent.signal_index] + "()" 20 return eval(eval_string) #return the signal generated by the corresponding method 19 21 20 def read_file(self , file_name, delimiter):21 22 def read_file(self): 23 22 24 try: 23 my_file = open( file_name, 'r')25 my_file = open(self.parent.file_name, 'r') 24 26 except IOError: 25 print "no file named " + file_name27 print "no file named " + self.parent.file_name 26 28 return [] #return an empty packet 27 29 … … 33 35 data_from_file.strip(']') #]'s will not be tollerated 34 36 35 data_from_file = data_from_file.split( delimiter) #break string into a list37 data_from_file = data_from_file.split(self.parent.delimiter) #break string into a list 36 38 37 39 return data_from_file 38 40 39 41 40 def gen_sine(self , freq, len):42 def gen_sine(self): 41 43 '''freq is frequency in cycles per packet. len is the length of the packet. type is the data type to return (e.g., "float", "short", "int")''' 42 44 43 45 count = 0 44 46 sine = [] 45 while count < len:46 sine.append(math.sin( freq*2*math.pi*count/len))47 while count < self.parent.len: 48 sine.append(math.sin(self.parent.freq*2*math.pi*count/self.parent.len)) 47 49 count = count + 1 48 50 … … 50 52 51 53 52 def gen_cosine(self , freq, len):54 def gen_cosine(self): 53 55 '''freq is frequency in cycles per packet. len is the length of the packet. type is the data type to return (e.g., "float", "short", "int")''' 54 56 55 57 count = 0 56 58 cosine = [] 57 while count < len:58 cosine.append(math.cos( freq*2*math.pi*count/len))59 while count < self.parent.len: 60 cosine.append(math.cos(self.parent.freq*2*math.pi*count/self.parent.len)) 59 61 count = count + 1 60 62 … … 63 65 64 66 65 def gen_random_data(self , len, rand_type):67 def gen_random_data(self): 66 68 '''the rand_type variable defines which function call to use in the random module''' 67 69 68 70 data = [] 69 rand_type =rand_type.lower() #makes comparison case insensitive70 if rand_type == 'random':71 tmp_rand_type = self.parent.rand_type.lower() #makes comparison case insensitive 72 if tmp_rand_type == 'random': 71 73 count = 0 72 while count < len:74 while count < self.parent.len: 73 75 data.append(random.random()) 74 76 count = count + 1 75 elif rand_type == 'uniform':77 elif tmp_rand_type == 'uniform': 76 78 count = 0 77 while count < len:79 while count < self.parent.len: 78 80 data.append(random.uniform()) 79 81 count = count + 1 … … 83 85 return data 84 86 85 def gen_zeros(self , len):87 def gen_zeros(self): 86 88 '''returns a list of zeros''' 87 89 data = [] 88 for n in range( len):90 for n in range(self.parent.len): 89 91 data.append(0) 90 92 return data