


figure;
hold off

plot(Bmap(:,1), Bmap(:,3));

z0 = -1.65;
zperiod = 0.5517;
nperiods = 6;
Lund = zperiod * nperiods;
Bamp = max(abs(Bmap(:,3)));

%  Bideal = @(z) piecewise(z<z0,0, z>(z0+Lund),0, Bamp * sin(2. * pi * z / zperiod));
unitstep = @(z) 0.5*(sign(z)+1.)
unitgate = @(z) unitstep(z) .* unitstep(-(z-1))
Bideal = @(z) Bamp* unitgate((z-z0)/Lund) .* cos(2*pi*(z-z0)/zperiod - pi)

hold on;
plot(Bmap(:,1), Bideal(Bmap(:,1)), 'color', 'red');
hold off;

Bmap(:,3) = Bideal(Bmap(:,1)); % OVERWRITING
Bmap(:,2) = 0.; % OVERWRITING





