% Play a "movie" of REFL_I in the PR vs. BS at various SR positions

function moviePR(opt)

  nIn = 2;
  fMod = 24.482e6;
  gMod = 0.4;
  order = 2;
  nDemod = 1;
  pDemod = zeros(opt.N, 1);

  N = 30;
  z = zeros(N^2, opt.Nopt);

  nxy = (1:N^2)' - 1;
  x = mod(nxy, N) * opt.lambda / (1.5 * N);
  y = floor(nxy/N) * opt.lambda / (3 * N);

  z(:,1) = x;   % PR position
  z(:,3) = y;   % BSa position
  z(:,4) = y;   % BSb position
  
  xx = reshape(x,N,N);
  yy = reshape(y,N,N);
  
  for n = 1:200
    z(:,2) = (n - 1) * opt.lambda / 50;
    [md, mp] = dcDemod(opt, nIn, fMod, gMod, order, nDemod, pDemod, z);

    dI = reshape(imag(md(:,1)),N,N);
    dQ = reshape(real(md(:,1)),N,N);
    pp = reshape(real(mp(:,1)),N,N);
    ps = reshape(real(mp(:,3)),N,N);
    
    clf
    subplot(2, 2, 1)
    surf(xx,yy, dI)
    hold on
    contour(xx,yy, dI, [0,0], 'k')
    view(2)
    shading interp
    title(sprintf('I phase (max %.4f)', max(max(abs(dI)))));
    hold off
    
    subplot(2, 2, 2)
    surf(xx,yy, dQ)
    hold on
    contour(xx,yy, dQ, [0,0], 'k')
    view(2)
    shading interp
    title(sprintf('Q phase (max %.4f)', max(max(abs(dQ)))));
    hold off
    
    subplot(2, 2, 3)
    surf(xx,yy, pp)
    view(2)
    shading interp
    title(sprintf('PR power (max %f)', max(max(abs(pp)))));

    subplot(2, 2, 4)
    surf(xx,yy, ps)
    view(2)
    shading interp
    title(sprintf('SR power (max %f)', max(max(abs(ps)))));
    xlabel(sprintf('SR at %d / 50 lambda', mod(n,50)));

    drawnow
  end
  
