Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/heterodyne.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 % HETERODYNE heterodynes time-series. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: HETERODYNE heterodynes time-series. | |
5 % | |
6 % The input signal is mixed down at the specified frequency. The mixed | |
7 % signal is then (optionally) low-pass filtered and (optionally) downsampled | |
8 % to have the specified bandwidth. | |
9 % | |
10 % CALL: b = heterodyne(a,pl) | |
11 % | |
12 % INPUTS: pl - a parameter list | |
13 % a - input analysis object | |
14 % | |
15 % OUTPUTS: b - output analysis object containing the filtered data. | |
16 % | |
17 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'heterodyne')">Parameters Description</a> | |
18 % | |
19 % VERSION: $Id: heterodyne.m,v 1.22 2011/04/08 08:56:16 hewitson Exp $ | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function varargout = heterodyne(varargin) | |
24 | |
25 % Check if this is a call for parameters | |
26 if utils.helper.isinfocall(varargin{:}) | |
27 varargout{1} = getInfo(varargin{3}); | |
28 return | |
29 end | |
30 | |
31 import utils.const.* | |
32 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
33 | |
34 % Collect input variable names | |
35 in_names = cell(size(varargin)); | |
36 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
37 | |
38 % Collect all AOs and plists | |
39 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
40 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
41 | |
42 % Make copies or handles to inputs | |
43 bs = copy(as, nargout); | |
44 | |
45 % Combine plists | |
46 pl = parse(pl, getDefaultPlist()); | |
47 | |
48 | |
49 % Get parameters | |
50 t0 = find(pl, 't0'); | |
51 f0 = find(pl, 'f0'); | |
52 if isempty(f0) | |
53 error('### Please specify the heterodyne frequency with the paramter ''f0'''); | |
54 end | |
55 mix = find(pl, 'quad'); | |
56 | |
57 for jj = 1:numel(bs) | |
58 if isa(bs(jj).data, 'tsdata') | |
59 | |
60 % store input history | |
61 inhist = bs(jj).hist; | |
62 | |
63 % check bandwidth | |
64 bw = find(pl, 'bw'); | |
65 if isempty(bw) | |
66 bw = bs(jj).data.fs; | |
67 end | |
68 if bw > bs(jj).data.fs | |
69 error('### The output bandwidth can not exceed the input bandwidth'); | |
70 end | |
71 | |
72 % mix at f0 | |
73 switch lower(mix) | |
74 case 'cos' | |
75 bs(jj).data.setY(bs(jj).data.getY .* 2.0 .* cos(2*pi * f0 .* (bs(jj).data.getX - t0))); | |
76 case 'sin' | |
77 bs(jj).data.setY(bs(jj).data.getY .* 2.0 .* sin(2*pi * f0 .* (bs(jj).data.getX - t0))); | |
78 otherwise | |
79 error('### Unknown quadrature specified'); | |
80 end | |
81 | |
82 | |
83 % user-input filter for low pass | |
84 filt = find(pl, 'filter'); | |
85 | |
86 % lowpass filter at bw/w | |
87 if ~isempty(filt) || utils.prog.yes2true(find(pl, 'lp')) | |
88 if isempty(filt) | |
89 % standard filter for low-pass | |
90 filt = miir(plist('type', 'lowpass', 'order', 4, 'fc', 0.4*bw, 'fs', bs(jj).data.fs)); | |
91 end | |
92 bs.filtfilt(filt); | |
93 end | |
94 | |
95 % downsample | |
96 if utils.prog.yes2true(find(pl, 'ds')) | |
97 factor = ceil(bs(jj).data.fs / bw); | |
98 bs.downsample(plist('factor', factor)); | |
99 end | |
100 | |
101 % set name and history | |
102 bs(jj).name = sprintf('heterodyne(%s, %s@%.01f Hz)', ao_invars{jj}, mix, f0); | |
103 bs(jj).addHistory(getInfo('None'), pl, ao_invars(jj), inhist); | |
104 % clear errors | |
105 bs(jj).clearErrors; | |
106 | |
107 else | |
108 error('### heterodyne only works on time-series AOs currently.'); | |
109 end | |
110 end | |
111 | |
112 % Set output | |
113 if nargout == numel(bs) | |
114 % List of outputs | |
115 for ii = 1:numel(bs) | |
116 varargout{ii} = bs(ii); | |
117 end | |
118 else | |
119 % Single output | |
120 varargout{1} = bs; | |
121 end | |
122 end | |
123 | |
124 %-------------------------------------------------------------------------- | |
125 % Get Info Object | |
126 %-------------------------------------------------------------------------- | |
127 function ii = getInfo(varargin) | |
128 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
129 sets = {}; | |
130 pls = []; | |
131 else | |
132 sets = {'Default'}; | |
133 pls = getDefaultPlist; | |
134 end | |
135 % Build info object | |
136 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: heterodyne.m,v 1.22 2011/04/08 08:56:16 hewitson Exp $', sets, pls); | |
137 ii.setModifier(false); | |
138 end | |
139 | |
140 %-------------------------------------------------------------------------- | |
141 % Get Default Plist | |
142 %-------------------------------------------------------------------------- | |
143 function plout = getDefaultPlist() | |
144 persistent pl; | |
145 if exist('pl', 'var')==0 || isempty(pl) | |
146 pl = buildplist(); | |
147 end | |
148 plout = pl; | |
149 end | |
150 | |
151 function pl = buildplist() | |
152 | |
153 pl = plist(); | |
154 | |
155 % f0 | |
156 p = param({'f0', 'The heterodyne frequency in Hz.'}, paramValue.EMPTY_DOUBLE); | |
157 pl.append(p); | |
158 | |
159 % t0 | |
160 p = param({'t0', 'Modulation start time offset in s.'}, paramValue.DOUBLE_VALUE(0)); | |
161 pl.append(p); | |
162 | |
163 % quad | |
164 p = param({'quad', 'The quadrature to output. ''sin'' or ''cos''.'},{2, {'sin', 'cos'}, paramValue.SINGLE}); | |
165 pl.append(p); | |
166 | |
167 % bw | |
168 p = param({'bw', 'The bandwidth at the output in Hz.'}, paramValue.EMPTY_DOUBLE); | |
169 pl.append(p); | |
170 | |
171 % lp | |
172 p = param({'lp', 'Low pass filter the output data at ''bw''.'}, paramValue.YES_NO); | |
173 pl.append(p); | |
174 | |
175 % filter | |
176 p = param({'filter', ['Filter to be used to low pass the output data.<br>' ... | |
177 'If this parameter is set, the low pass is applied regardless to the value of the ''lp'' parameter']}, paramValue.EMPTY_DOUBLE); | |
178 pl.append(p); | |
179 | |
180 % ds | |
181 p = param({'ds','Downsample the output data.'}, paramValue.YES_NO); | |
182 pl.append(p); | |
183 end |