diff m-toolbox/test/test_ao_heterodyne.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/test/test_ao_heterodyne.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,49 @@
+% Tests for ao/heterodyne
+%
+% $Id: test_ao_heterodyne.m,v 1.4 2010/07/08 08:49:37 mauro Exp $
+%
+
+%% produce input signal
+
+fs = 10;
+nsecs = 1000;
+amplitude = 1e-3;
+noise = 1e-6;
+fmod = 0.1;
+yunits = 'V';
+
+% carrier
+h = ao(plist('waveform', 'sine', 'f', fmod, 'a', 1, 'fs', fs, 'nsecs', nsecs, 'yunits', yunits));
+% signal
+s = ao(plist('waveform', 'sine', 'f', 5e-3, 'a', 1, 'fs', fs, 'nsecs', nsecs));
+% modulate the carrier
+m = h .* s;
+% add noise
+n = ao(plist('waveform', 'noise', 'nsecs', nsecs, 'fs', fs, 'sigma', noise, 'yunits', yunits));
+
+a1 = m + n; 
+
+%% demodulate
+b1_cos = a1.heterodyne(plist('f0', fmod, 'bw', fmod, 'quad', 'cos'));
+b1_sin = a1.heterodyne(plist('f0', fmod, 'bw', fmod, 'quad', 'sin'));
+
+iplot(s, b1_cos, b1_sin, plist('linestyles', {'-','none','none'}, 'markers', {'none','+','+'}));
+
+%% demodulate without downsampling
+b1_cos = a1.heterodyne(plist('f0', fmod, 'ds', false, 'bw', fmod, 'quad', 'cos'));
+b1_sin = a1.heterodyne(plist('f0', fmod, 'ds', false, 'bw', fmod, 'quad', 'sin'));
+
+iplot(s, b1_cos, b1_sin);
+
+%% demodulate without downsampling and low pass filtering
+b1_cos = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'cos'));
+b1_sin = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'sin'));
+
+iplot(s, b1_cos, b1_sin);
+
+%% demodulate without downsampling, but with low pass filtering from user input
+filt = miir(plist('type', 'lowpass', 'order', 2, 'fc', 0.2*fmod, 'fs', a1.data.fs));
+b1_cos = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'cos', 'filter', filt));
+b1_sin = a1.heterodyne(plist('f0', fmod, 'ds', false, 'lp', false, 'bw', fmod, 'quad', 'sin', 'filter', filt));
+
+iplot(s, b1_cos, b1_sin);
\ No newline at end of file