% General parameters for testing CCD frame transfer and inversion.
% Time units are seconds. Counts are CCD electrons. 
% Assume 1 electron per detected photon.

T = 0.01 % s exposure time. Try 0.01 s (video rate) to show streaks clearly.
   % Realistically, > 1.0 s at 100% duty cycle with 2 port readout,
   % for an ADC rate around 1 MHz. But faster ADCs exist, and so
   % do schemes with more ports and masks on both sides.
   % 
   % The ADC and shift register can be faster than the
   % vertical shift, just not fast enough to read out the 
   % whole image in the time it takes to shift the image 
   % under the mask. That is why frame transfer helps!
f = 0.3e6 % Hz (rows per second) shift rate (0.3 MHz is realistic)
contrast = 0.3 % contrast parameter for image display
   % <1 helps to bring out faint features.
meancounts = 1000 % mean counts per pixel for observation
N_ports = 2 % multi-port readout lets the ADC run proportionately slower.

% First load the lightning image, scale and display it.
image_color = imread('150599main_lightning_photo.jpg');
image = sum(image_color,3);
isize = size(image);
Nx = isize(2); % number of columns
Ny = isize(1); % number of rows
% Impose desired mean count rate
countrate = meancounts/T % counts per second per pixel
image = sum(image_color,3);
image *= countrate / mean(image(:));

% Some useful, calculated stats
frame_transfer_time = Ny/f
implied_min_ADC_rate = Nx*Ny/(T - frame_transfer_time)/N_ports
   % This just assumes continuous readout, 100% duty cycle.
smearing_percent = 100*frame_transfer_time/T
