%
% Read Noise Calculation
% -------------------------
% This file collates all the data collected for read noise and calculates various
% parameters, including the average pixel value and the read noise for the
% pixel postions that we have chosen.
% The data collected is saved to be used for analysis later.

clear all;
clc;
close all;

% Parameters
nfiles = 100;                    % no.of files to calculate
pixels = [1,1;2,2;3,3;4,4];     % position of each pixel
npixels = 100;                    % no. of pixels to calculate

% Matrix for storing data
org = zeros(nfiles,4); % original data
ave = zeros(npixels, 4);
variance = zeros(npixels,4);


% reads data;
for j = 1:npixels,
    for i=1:nfiles,
        num = num2str(i);
        if(i<10) name = strcat('dc0', num, '.NEF'); 
        elseif (i>=10 & i<100) name = strcat('dc', num, '.nef'); 
        else name = strcat('dc', num, '.nef'); end;
        data = double(nefread(name));
        org(i,:) = data(pixels(j,1),pixels(j,2),:);        
    end;
    ave(j,:) = mean(org);       % time average for the pixel for each column
    variance(j,:) = var(org);
    j
end;

save readnoise1;