%
% Make a 2D circularly symmetric cosine chirp image.
%
% - the chirp will start at DC in the center of the image.
% - the IF increases linearly along radials away from the center.
% - optionally, add Gaussian AM.
%

%
% Initialize user parameters
%
Nrows = 256;             % number of rows in image
Ncols = 256;             % number of cols in image
fmax_cpi = 23;           % max chirp freq in cycles per image
Use_Gaussian_AM = 'no';  % 'yes' or 'no'
sigma = 72;              % space constant for Gaussian AM




Xc = (Ncols + 1)/2;      % coordinates of image center
Yc = (Nrows + 1)/2;

%
% calculate max chirp freq in radians/pix
%
fmax = 2*pi*fmax_cpi/max([Nrows Ncols]);

[X,Y] = meshgrid(1:Ncols,1:Nrows);  % grid of pixel coordinates

R = sqrt((X-Xc).^2 + (Y-Yc).^2);    % radial distance to image center
Rmax = max(R(:));                   % max distance to image center
                                    %  (fmax will be achieved here)
A = fmax/(2*Rmax);
chirp = cos(A*R.^2);                % make the chirp image

%
% Optionally add Gaussian AM
%
if (strcmp(Use_Gaussian_AM,'yes'))
  chirp = chirp .* exp(-R.^2/(2*sigma^2));
end

%
% display the chirp; the pixels are in the range [-1,1]
%
figure(1);
imshow(chirp,[]);
title('Chirp w/ pix in [-1,1]');

%
% convert to one byte per pixel with pixels in the range [0,255]
%
xMax = max(chirp(:));
xMin = min(chirp(:));
ScaleFactor = 255.0 / (xMax - xMin);
byte_chirp = uint8(round((chirp - xMin) * ScaleFactor));

%
% display byte_chirp
%
figure(2);
imshow(byte_chirp);
title('Byte Chirp w/ pix in [0,255]');

