%clear; close all;

if( ~exist('scan') )  load radarData200516.mat, end

X = NaN(length(scan(1).pulse(1).radarVideo), length(scan(1).pulse));
Y = NaN(length(scan(1).pulse(1).radarVideo), length(scan(1).pulse));


for m = 2:length(scan)
  
  pulses = scan(m).pulse;
  figure;
  
  for n = 1:length(pulses)
    pulse = pulses(n);
    
    % angle comes either from azimuth or pointing angle, in radians
    azimuth = ones(1, length(pulse.radarVideo))* pulse.azimuth * pi/180;
    
    % range is self described, convert to array
    range = linspace(pulse.startRange, pulse.endRange, length(pulse.radarVideo));
    
    % convert to cartesian
    [ x, y ] = pol2cart(azimuth, range);
    X(:,n) = x';
    Y(:,n) = y';

    % plot and map colors to values
    %scatter3(x,y,pulse.radarVideo,3,pulse.radarVideo);
    %scatter(x,y,3,pulse.radarVideo);
    %hold on;
  end

  %plotmatrix(x,y,3,pulse.radarVideo);
  plotmatrix(X,Y)
  
  title(['Scan ' num2str(m)]);
  axis equal;
  %view(0,90);
  
  
  % hey slow down just plot 1 scan for now
  break;
end
