Mercurial > hg > ltpda
comparison m-toolbox/classes/@sigBuilder/cb_addSignal.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % CB_ADDSIGNAL callback fires when the user clicks 'add signal' | |
2 % | |
3 % M Hewitson | |
4 % | |
5 % $Id: cb_addSignal.m,v 1.1 2008/10/19 11:42:40 hewitson Exp $ | |
6 % | |
7 function cb_addSignal(varargin) | |
8 | |
9 myh = varargin{1}; | |
10 mainfig = varargin{end}; | |
11 | |
12 % sigType handle | |
13 sh = findobj(mainfig.handle, 'Tag', 'SignalTypeSelect'); | |
14 | |
15 % Get selected signal | |
16 val = get(sh, 'Value'); | |
17 sigs = get(sh, 'String'); | |
18 sig = sigs{val}; | |
19 | |
20 % Build signals | |
21 switch lower(sig) | |
22 case 'sine wave' | |
23 obj = buildSineWave(mainfig); | |
24 case 'white noise' | |
25 obj = buildWhiteNoise(mainfig); | |
26 case 'chirp' | |
27 obj = buildChirp(mainfig); | |
28 case 'gaussian pulse' | |
29 obj = buildGaussPulse(mainfig); | |
30 case 'square wave' | |
31 obj = buildSquarewave(mainfig); | |
32 case 'sawtooth' | |
33 obj = buildSawtooth(mainfig); | |
34 case 'noise generator' | |
35 obj = buildNoiseGen(mainfig); | |
36 case 'polynomial' | |
37 obj = buildPolynomial(mainfig); | |
38 case 'custom' | |
39 obj = buildCustom(mainfig); | |
40 otherwise | |
41 error('### I can''t build signal ''%s'' yet', sig); | |
42 end | |
43 | |
44 % Add this AO | |
45 mainfig.signals = [mainfig.signals obj]; | |
46 | |
47 % Refresh list | |
48 refreshSignalList(mainfig); | |
49 | |
50 end | |
51 | |
52 %-------------------------------------------------------------------------- | |
53 % Build a noisegenerator signal | |
54 function obj = buildPolynomial(mainfig) | |
55 | |
56 [fs, t0, name] = getFsT0(mainfig); | |
57 | |
58 % get coeffs | |
59 h = findobj(mainfig.handle, 'Tag', 'Poly_Coeffs'); | |
60 coeffs = eval(['[' get(h, 'String') ']']); | |
61 if isempty(name) || strcmpi(name, 'none') | |
62 name = sprintf('poly(%s)', mat2str(coeffs)); | |
63 end | |
64 % get Nsecs | |
65 h = findobj(mainfig.handle, 'Tag', 'Poly_Length'); | |
66 Nsecs = eval(['[' get(h, 'String') ']']); | |
67 % Build | |
68 obj = ao(plist('polyval', coeffs, ... | |
69 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
70 end | |
71 | |
72 %-------------------------------------------------------------------------- | |
73 % Build a noisegenerator signal | |
74 function obj = buildNoiseGen(mainfig) | |
75 | |
76 [fs, t0, name] = getFsT0(mainfig); | |
77 | |
78 % get f0 | |
79 h = findobj(mainfig.handle, 'Tag', 'NoiseGen_Gain'); | |
80 g = eval(get(h, 'String')); | |
81 % get poles | |
82 h = findobj(mainfig.handle, 'Tag', 'NoiseGen_Poles'); | |
83 poles = eval(get(h, 'String')); | |
84 % get zeroes | |
85 h = findobj(mainfig.handle, 'Tag', 'NoiseGen_Zeros'); | |
86 zeros = eval(get(h, 'String')); | |
87 if isempty(name) || strcmpi(name, 'none') | |
88 name = sprintf('noisegen'); | |
89 end | |
90 % get Nsecs | |
91 h = findobj(mainfig.handle, 'Tag', 'NoiseGen_Length'); | |
92 Nsecs = eval(['[' get(h, 'String') ']']); | |
93 % Build | |
94 pzm = pzmodel(g, poles, zeros); | |
95 obj = ao(plist('pzmodel', pzm, ... | |
96 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
97 end | |
98 | |
99 %-------------------------------------------------------------------------- | |
100 % Build a sawtooth signal | |
101 function obj = buildSawtooth(mainfig) | |
102 | |
103 [fs, t0, name] = getFsT0(mainfig); | |
104 | |
105 % get f0 | |
106 h = findobj(mainfig.handle, 'Tag', 'Sawtooth_F'); | |
107 f0 = eval(get(h, 'String')); | |
108 % get duty | |
109 h = findobj(mainfig.handle, 'Tag', 'Sawtooth_Width'); | |
110 wd = eval(get(h, 'String')); | |
111 if isempty(name) || strcmpi(name, 'none') | |
112 name = sprintf('saw(%g)', f0); | |
113 end | |
114 % get Nsecs | |
115 h = findobj(mainfig.handle, 'Tag', 'Sawtooth_Length'); | |
116 Nsecs = eval(['[' get(h, 'String') ']']); | |
117 % Build | |
118 obj = ao(plist('waveform', 'Sawtooth', ... | |
119 'f0', f0, 'width', wd, ... | |
120 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
121 end | |
122 | |
123 %-------------------------------------------------------------------------- | |
124 % Build a square wave signal | |
125 function obj = buildSquarewave(mainfig) | |
126 | |
127 [fs, t0, name] = getFsT0(mainfig); | |
128 | |
129 % get f0 | |
130 h = findobj(mainfig.handle, 'Tag', 'SquareWave_F'); | |
131 f0 = eval(get(h, 'String')); | |
132 % get duty | |
133 h = findobj(mainfig.handle, 'Tag', 'SquareWave_Duty'); | |
134 duty = eval(get(h, 'String')); | |
135 if isempty(name) || strcmpi(name, 'none') | |
136 name = sprintf('square(%g)', f0); | |
137 end | |
138 % get Nsecs | |
139 h = findobj(mainfig.handle, 'Tag', 'SquareWave_Length'); | |
140 Nsecs = eval(['[' get(h, 'String') ']']); | |
141 % Build | |
142 obj = ao(plist('waveform', 'Square wave', ... | |
143 'f0', f0, 'duty', duty, ... | |
144 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
145 end | |
146 | |
147 %-------------------------------------------------------------------------- | |
148 % Build a gauss pulse signal | |
149 function obj = buildGaussPulse(mainfig) | |
150 | |
151 [fs, t0, name] = getFsT0(mainfig); | |
152 | |
153 % get f0 | |
154 h = findobj(mainfig.handle, 'Tag', 'GPulse_F0'); | |
155 f0 = eval(get(h, 'String')); | |
156 % get BW | |
157 h = findobj(mainfig.handle, 'Tag', 'GPulse_BW'); | |
158 bw = eval(get(h, 'String')); | |
159 if isempty(name) || strcmpi(name, 'none') | |
160 name = sprintf('gpulse(%g)', f0); | |
161 end | |
162 % get Nsecs | |
163 h = findobj(mainfig.handle, 'Tag', 'GPulse_Length'); | |
164 Nsecs = eval(['[' get(h, 'String') ']']); | |
165 % Build | |
166 obj = ao(plist('waveform', 'Gaussian pulse', ... | |
167 'f0', f0, 'bw', bw, ... | |
168 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
169 end | |
170 | |
171 | |
172 %-------------------------------------------------------------------------- | |
173 % Build a chirp signal | |
174 function obj = buildChirp(mainfig) | |
175 | |
176 [fs, t0, name] = getFsT0(mainfig); | |
177 | |
178 % get f0 | |
179 h = findobj(mainfig.handle, 'Tag', 'Chirp_F0'); | |
180 f0 = eval(get(h, 'String')); | |
181 % get f1 | |
182 h = findobj(mainfig.handle, 'Tag', 'Chirp_F1'); | |
183 f1 = eval(get(h, 'String')); | |
184 if isempty(name) || strcmpi(name, 'none') | |
185 name = sprintf('chirp(%g->%g)', f0,f1); | |
186 end | |
187 % get T1 | |
188 h = findobj(mainfig.handle, 'Tag', 'Chirp_T1'); | |
189 t1 = eval(get(h, 'String')); | |
190 % get Nsecs | |
191 h = findobj(mainfig.handle, 'Tag', 'Chirp_Length'); | |
192 Nsecs = eval(['[' get(h, 'String') ']']); | |
193 % Build | |
194 obj = ao(plist('waveform', 'chirp', ... | |
195 'f0', f0, 'f1', f1, 't1', t1, ... | |
196 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
197 end | |
198 | |
199 | |
200 %-------------------------------------------------------------------------- | |
201 % Build a custom signal | |
202 function obj = buildCustom(mainfig) | |
203 | |
204 [fs, t0, name] = getFsT0(mainfig); | |
205 | |
206 % get type | |
207 h = findobj(mainfig.handle, 'Tag', 'Custom_Fcn'); | |
208 fcn = get(h, 'String'); | |
209 if isempty(name) || strcmpi(name, 'none') | |
210 name = fcn; | |
211 end | |
212 % get Nsecs | |
213 h = findobj(mainfig.handle, 'Tag', 'Custom_Length'); | |
214 Nsecs = eval(['[' get(h, 'String') ']']); | |
215 % Build | |
216 obj = ao(plist('tsfcn', fcn, ... | |
217 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
218 end | |
219 | |
220 | |
221 %-------------------------------------------------------------------------- | |
222 % Build a white noise | |
223 function obj = buildWhiteNoise(mainfig) | |
224 | |
225 [fs, t0, name] = getFsT0(mainfig); | |
226 | |
227 % get type | |
228 h = findobj(mainfig.handle, 'Tag', 'WhiteNoise_Type'); | |
229 types = get(h, 'String'); | |
230 type = types{get(h, 'Value')}; | |
231 if strcmpi(name, 'none') || isempty(name) | |
232 name = type; | |
233 end | |
234 % get Sigma | |
235 h = findobj(mainfig.handle, 'Tag', 'WhiteNoise_Sigma'); | |
236 sigma = eval(['[' get(h, 'String') ']']); | |
237 % get Nsecs | |
238 h = findobj(mainfig.handle, 'Tag', 'WhiteNoise_Length'); | |
239 Nsecs = eval(['[' get(h, 'String') ']']); | |
240 % Build | |
241 obj = ao(plist('waveform', 'noise', ... | |
242 'type', type, 'sigma', sigma, ... | |
243 'nsecs', Nsecs, 'fs', fs, 't0', t0, 'name', name)); | |
244 end | |
245 | |
246 %-------------------------------------------------------------------------- | |
247 % Build a sine wave | |
248 function obj = buildSineWave(mainfig) | |
249 | |
250 [fs, t0, name] = getFsT0(mainfig); | |
251 | |
252 % get amplitudes | |
253 h = findobj(mainfig.handle, 'Tag', 'SineWave_Amplitudes'); | |
254 amps = eval(['[' get(h, 'String') ']']); | |
255 % get frequencies | |
256 h = findobj(mainfig.handle, 'Tag', 'SineWave_Frequencies'); | |
257 freqs = eval(['[' get(h, 'String') ']']); | |
258 % get phases | |
259 h = findobj(mainfig.handle, 'Tag', 'SineWave_Phases'); | |
260 phases = eval(['[' get(h, 'String') ']']); | |
261 % get Nsecs | |
262 h = findobj(mainfig.handle, 'Tag', 'SineWave_Lengths'); | |
263 Nsecs = eval(['[' get(h, 'String') ']']); | |
264 % get Toffs | |
265 h = findobj(mainfig.handle, 'Tag', 'SineWave_Starts'); | |
266 Toffs = eval(['[' get(h, 'String') ']']); | |
267 if strcmpi(name, 'none') || isempty(name) | |
268 name = 'sin('; | |
269 name = [name sprintf('%.2g,', freqs)]; | |
270 name = [name(1:end-1) ')']; | |
271 end | |
272 | |
273 % Build | |
274 obj = ao(plist('waveform', 'sine wave', ... | |
275 'A', amps, 'f', freqs, 'phi', phases*pi/180, ... | |
276 'nsecs', Nsecs, 'toff', Toffs, 'fs', fs, 't0', t0, 'name', name)); | |
277 | |
278 end | |
279 | |
280 %-------------------------------------------------------------------------- | |
281 % Retrieve the sample rate and start time and name | |
282 % | |
283 function [fs, t0, name] = getFsT0(mainfig) | |
284 % name | |
285 h = findobj(mainfig.handle, 'Tag', 'NameEdit'); | |
286 name = get(h, 'String'); | |
287 % T0 | |
288 h = findobj(mainfig.handle, 'Tag', 'T0edit'); | |
289 t0 = time(get(h, 'String')); | |
290 % FS | |
291 h = findobj(mainfig.handle, 'Tag', 'SampleRateEdit'); | |
292 fs = eval(get(h, 'String')); | |
293 end | |
294 | |
295 |