1function trig = makeDigitalOutputPulse(channel, varargin)
2%makeDigitalOutputPulse Create a digital output pulse event a.k.a. trigger.
3% trig_out=makeDigitalOutputPulse() Create an output trigger event on a
4% given channel with optional given delay and
5% duration.
6% Possible channel values: 'osc0','osc1','ext1'
7%
8% See also Sequence.addBlock
10persistent parser
11if isempty(parser)
12 parser = inputParser;
13 parser.FunctionName = 'makeDigitalOutputPulse';
15 addParamValue(parser, 'delay', 0, @isnumeric);
16 addParamValue(parser, 'duration', 0, @isnumeric); % will replace with gradRadterTime below
17 addParamValue(parser, 'system', [], @isstruct);
18end
20if nargin<1
21 error('makeDigitalOutputPulse:invalidArguments','Must supply a channel');
22end
24parse(parser, varargin{:});
25opt = parser.Results;
27if isempty(opt.system)
28 system=mr.opts();
29else
30 system=opt.system;
31end
33channel_num=find(strcmp(channel,{'osc0','osc1','ext1'}));
34assert(~isempty(channel_num) && channel_num>0,'makeDigitalOutputPulse:invalidChannel',...
35 'Channel (%s) is invalid',channel);
36trig.type = 'output';
37trig.channel=channel;
38trig.delay = opt.delay;
39trig.duration = opt.duration;
40if (trig.duration<=system.gradRasterTime)
41 trig.duration=system.gradRasterTime;
42end
44end