0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % Tests for ao/heterodyne
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % $Id: test_ao_heterodyne.m,v 1.4 2010/07/08 08:49:37 mauro Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %% produce input signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 fs = 10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 nsecs = 1000;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 amplitude = 1e-3;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 noise = 1e-6;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 fmod = 0.1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 yunits = 'V';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % carrier
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 h = ao(plist('waveform', 'sine', 'f', fmod, 'a', 1, 'fs', fs, 'nsecs', nsecs, 'yunits', yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 s = ao(plist('waveform', 'sine', 'f', 5e-3, 'a', 1, 'fs', fs, 'nsecs', nsecs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % modulate the carrier
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 m = h .* s;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % add noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 n = ao(plist('waveform', 'noise', 'nsecs', nsecs, 'fs', fs, 'sigma', noise, 'yunits', yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 a1 = m + n;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 %% demodulate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 b1_cos = a1.heterodyne(plist('f0', fmod, 'bw', fmod, 'quad', 'cos'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 b1_sin = a1.heterodyne(plist('f0', fmod, 'bw', fmod, 'quad', 'sin'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 iplot(s, b1_cos, b1_sin, plist('linestyles', {'-','none','none'}, 'markers', {'none','+','+'}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 %% demodulate without downsampling
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 b1_cos = a1.heterodyne(plist('f0', fmod, 'ds', false, 'bw', fmod, 'quad', 'cos'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 b1_sin = a1.heterodyne(plist('f0', fmod, 'ds', false, 'bw', fmod, 'quad', 'sin'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 iplot(s, b1_cos, b1_sin);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 %% demodulate without downsampling and low pass filtering
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 b1_cos = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'cos'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 b1_sin = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'sin'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 iplot(s, b1_cos, b1_sin);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 %% demodulate without downsampling, but with low pass filtering from user input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 filt = miir(plist('type', 'lowpass', 'order', 2, 'fc', 0.2*fmod, 'fs', a1.data.fs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 b1_cos = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'cos', 'filter', filt));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 b1_sin = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'sin', 'filter', filt));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 iplot(s, b1_cos, b1_sin); |