From dc53f425584f3f095ca55b404c0e235602f640f3 Mon Sep 17 00:00:00 2001 From: rmoskwa Date: Sat, 25 Apr 2026 19:23:36 -0500 Subject: [PATCH] Enforce maxGrad/maxSlew in makeExtendedTrapezoid.m --- matlab/+mr/makeExtendedTrapezoid.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/matlab/+mr/makeExtendedTrapezoid.m b/matlab/+mr/makeExtendedTrapezoid.m index 1828a44..e9e4380 100644 --- a/matlab/+mr/makeExtendedTrapezoid.m +++ b/matlab/+mr/makeExtendedTrapezoid.m @@ -84,6 +84,15 @@ if any(abs(round(opt.times/system.gradRasterTime)*system.gradRasterTime-opt.times)>1e-8) % 10ns is an acceptable rounding error error('All time points must be on a gradient raster or "convert2arbitrary" option must be used.'); end + % check slew rate and gradient amplitude against the active limits + % the convert2arbitrary branch above gets these checks via mr.makeArbitraryGrad + slew = (opt.amplitudes(2:end)-opt.amplitudes(1:end-1)) ./ (opt.times(2:end)-opt.times(1:end-1)); + if ~isempty(slew) && max(abs(slew))>maxSlew + error('Slew rate violation (%.0f%%)',max(abs(slew))/maxSlew*100); + end + if max(abs(opt.amplitudes))>maxGrad + error('Gradient amplitude violation (%.0f%%)',max(abs(opt.amplitudes))/maxGrad*100); + end % grad.type = 'grad'; grad.channel = opt.channel;