/ concept-collection / seqlab
Sign in
concept-collection / seqlab
seqlab / src / engine / pulseq / +mr / splitGradient.m
82 lines · 2.9 KBCodeBlameHistory
78d04f1seqlab: write and view pulseq MRI sequences in the browserJeremy Magland 1function [grads] = splitGradient(grad, varargin)
2%SplitGradient Splits a trapezoidal gradient into slew up, flat top and
3%slew down.
4%
5% [grads] = splitGradient(grad)
6% Returns the individual gradient parts (slew up, flat top and slew down)
7% as extended trapezoid gradient objects. The delays in the individual
8% gradient events are adapted such that addGradients(...) produces an
9% gradient equivalent to 'grad'.
10%
11% See also splitGradientAt makeExtendedTrapezoid makeTrapezoid
12% Sequence.addBlock mr.opts
13%
14% Stefan Kroboth <stefan.kroboth@uniklinik-freiburg.de>
16persistent parser
18if isempty(parser)
19 parser = mr.aux.InputParserCompat;
20 parser.FunctionName = 'splitGradient';
21 parser.addRequired('grad', @isstruct);
22 parser.addOptional('system', [], @isstruct);
23end
24parse(parser, grad, varargin{:});
25opt = parser.Results;
27if isempty(opt.system)
28 system=mr.opts();
29else
30 system=opt.system;
31end
33gradRasterTime = system.gradRasterTime;
34total_length = mr.calcDuration(grad);
36if strcmp(grad.type, 'trap')
37 ch = grad.channel;
38 grad.delay = round(grad.delay /gradRasterTime)*gradRasterTime; % MZ: was ceil
39 grad.riseTime = round(grad.riseTime/gradRasterTime)*gradRasterTime; % MZ: was ceil
40 grad.flatTime = round(grad.flatTime/gradRasterTime)*gradRasterTime; % MZ: was ceil
41 grad.fallTime = round(grad.fallTime/gradRasterTime)*gradRasterTime; % MZ: was ceil
43 % ramp up
44 times = [0, grad.riseTime];
45 amplitudes = [0 grad.amplitude];
46 rampup = mr.makeExtendedTrapezoid(ch, 'system', system, 'times', times,...
47 'amplitudes', amplitudes, ...
48 'skip_check', true);
49 rampup.delay = grad.delay;
50% rampup.t = rampup.t;
53 % ramp down
54 times = [0, grad.fallTime];
55 amplitudes = [grad.amplitude 0];
56 rampdown = mr.makeExtendedTrapezoid(ch, 'system', system, 'times', times,...
57 'amplitudes', amplitudes, ...
58 'skip_check', true);
59 rampdown.delay = total_length - grad.fallTime;
60 %rampdown.t = rampdown.t*gradRasterTime;
62 % flattop
63 if grad.flatTime > eps
64 times = [0, grad.flatTime];
65 amplitudes = [grad.amplitude grad.amplitude ];
66 flattop = mr.makeExtendedTrapezoid(ch, 'system', system, 'times', times,...
67 'amplitudes', amplitudes, ...
68 'skip_check', true);
69 flattop.delay = (grad.delay + grad.riseTime);
70 else
71 % triangle -- no flatTop
72 flattop=[];
73 end
75 grads = [rampup flattop rampdown];
76elseif strcmp(grad.type, 'grad')
77 error('Splitting of arbitrary gradients is not implemented yet.');
78else
79 error('Splitting of unsupported event.');
80end
82end
moveopenescclose