Home > classes > @ao > fromWaveform.m

fromWaveform

PURPOSE ^

FROMWAVEFORM Construct an ao from a waveform

SYNOPSIS ^

function a = fromWaveform(a, pli)

DESCRIPTION ^

 FROMWAVEFORM Construct an ao from a waveform
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FUNCTION:    fromWaveform

 DESCRIPTION: Construct an ao from a waveform

 CALL:        a = fromWaveform(pl)

 PARAMETER:
              pl:       Parameter list object

 HISTORY:     07-05-2007 Hewitson
              Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % FROMWAVEFORM Construct an ao from a waveform
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % FUNCTION:    fromWaveform
0005 %
0006 % DESCRIPTION: Construct an ao from a waveform
0007 %
0008 % CALL:        a = fromWaveform(pl)
0009 %
0010 % PARAMETER:
0011 %              pl:       Parameter list object
0012 %
0013 % HISTORY:     07-05-2007 Hewitson
0014 %              Creation
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 function a = fromWaveform(a, pli)
0018 
0019   VERSION = '$Id: fromWaveform.m,v 1.10 2008/09/04 13:37:14 ingo Exp $';
0020 
0021   % get AO info
0022   ii = ao.getInfo('ao', 'From Waveform');
0023 
0024   % Set the method version string in the minfo object
0025   ii.setMversion([VERSION '-->' ii.mversion]);
0026 
0027   % Add default values
0028   pl = combine(pli, ii.plists);
0029 
0030   nsecs  = find(pl, 'nsecs');
0031   fs     = find(pl, 'fs');
0032   t0     = find(pl, 't0');
0033   if isempty(t0)
0034     t0 = time(0);
0035   end
0036 
0037   waveform = lower(find(pl, 'waveform'));
0038   switch waveform
0039     %------------ Sine Wave
0040     case {'sine wave','sinewave','sine-wave'}
0041       ampl = find(pl, 'A');
0042       freq = find(pl, 'f');
0043       phi  = find(pl, 'phi');
0044 
0045       if length(ampl) ~= length(freq) || length(freq) ~= length(phi) || length(ampl) ~= length(phi)
0046         error('### Provide an Amplitude, frequency and phase for each sine-wave in the series.');
0047       end
0048 
0049       if isempty(ampl)
0050         ampl = 1;
0051       end
0052       if isempty(freq)
0053         freq = 1;
0054       end
0055       if isempty(phi)
0056         phi = 0;
0057       end
0058 
0059       % build command
0060       tsfcn = '';
0061       for jj=1:length(ampl)
0062         amp = ampl(jj);
0063         fr = freq(jj);
0064         ph = phi(jj);
0065 
0066         if jj==1
0067           tsfcn = sprintf('%g*sin(2*pi*%g*t + %g*pi/180)', amp, fr, ph);
0068         else
0069           tsfcn = [tsfcn sprintf(' + %g*sin(2*pi*%g*t + %g*pi/180)', amp, fr, ph)];
0070         end
0071       end
0072 
0073       %------------ Noise
0074     case 'noise'
0075       ntype = find(pl, 'type');
0076       if isempty(ntype)
0077         ntype = 'Normal';
0078       end
0079 
0080       randn_state = find(pl, 'rand_state');
0081 
0082       switch lower(ntype)
0083         case 'normal'
0084           tsfcn = 'randn(size(t))';
0085           % Set random state
0086           if ~isempty(randn_state)
0087             randn('state',randn_state);
0088           else
0089             randn_state = randn('state');
0090             pl.append('rand_state', randn_state);
0091           end
0092 
0093         case 'uniform'
0094           tsfcn = 'rand(size(t))';
0095           % Set random state
0096           if ~isempty(randn_state)
0097             rand('seed',randn_state);
0098           else
0099             randn_state = rand('seed');
0100             pl.append('rand_state', randn_state);
0101           end
0102 
0103       end
0104       %------------ Chirp
0105     case 'chirp'
0106       f0  = find(pl, 'f0');
0107       fe  = find(pl, 'f1');
0108       te  = find(pl, 't1');
0109       if isempty(f0)
0110         f0 = 0;
0111       end
0112       if isempty(fe)
0113         fe = fs/2;
0114       end
0115       if isempty(te)
0116         te = nsecs;
0117       end
0118       tsfcn = sprintf('chirp(t,%g,%g,%g)', f0, fe, te);
0119       %------------ Gaussian pulse
0120     case {'gaussian pulse','gaussian-pulse'}
0121       fc  = find(pl, 'f0');
0122       bw  = find(pl, 'bw');
0123       if isempty(fc)
0124         fc = 1;
0125       end
0126       if isempty(bw)
0127         bw = fs/2;
0128       end
0129       tsfcn = sprintf('gauspuls(t,%g,%g)', fc, bw);
0130     case {'square wave','squarewave','square-wave'}
0131       freq = find(pl, 'f');
0132       duty = find(pl, 'duty');
0133       if isempty(freq)
0134         freq = 1;
0135       end
0136       if isempty(duty)
0137         duty = 50;
0138       end
0139       tsfcn = sprintf('square(2*pi*%g*t,%g)', freq, duty);
0140     case {'saw tooth','sawtooth','saw-tooth'}
0141       freq  = find(pl, 'f');
0142       width = find(pl, 'width');
0143       if isempty(freq)
0144         freq = 1;
0145       end
0146       if isempty(width)
0147         width = 0.5;
0148       end
0149       tsfcn = sprintf('sawtooth(2*pi*%g*t,%g)', freq, width);
0150   end
0151 
0152 
0153   % construct tsdata
0154   t = linspace(0, nsecs-1/fs, nsecs*fs);
0155   % make y data
0156   y = eval([tsfcn ';']);
0157 
0158   ts = tsdata(t,y);
0159   ts.setXunits('s');
0160   ts.setYunits('V');
0161   ts.setT0(t0);
0162 
0163   % Make an analysis object
0164   a.data  = ts;
0165   a.setName(waveform, 'internal');
0166   % Add history
0167   a.addHistory(ii, pl, [], []);
0168 
0169 end
0170

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003