%
% Plotting Average Read Noise
% ------------------------------
% This program analyzes the read noise data collected and plots a graph for
% the various channels on the same graph so that we can analyze the data visually.
%


close all;
clear;
clc;

load read_noise.mat;
mean1 = mean(variance_1);       % calculates average read noise for the exposure
mean2 = mean(variance_2);
mean4 = mean(variance_4);
mean8 = mean(variance_8);
mean15 = mean(variance_15);
mean20 = mean(variance_20);
mean25 = mean(variance_25);
mean30 = mean(variance_30);


figure(1);
hold on;
for i = 1:1,
    for j = 1:4,
variation = [mean1(i,j);
    mean2(i,j);
    mean4(i,j);
    mean8(i,j);
    mean15(i,j);
    mean20(i,j);
    mean25(i,j);
    mean30(i,j)];
if (j==1) x='r'; end
if (j==2) x='g';end
if (j==3) x='b';end
if (j==4) x='g--';end

%plot([1 2 4 8 15 20 25 30], variation',x);
    end
end

variation = [mean1;mean2;mean4;mean8;mean15;mean20;mean25;mean30];
variation2 = [variation(:,1) mean([variation(:,2) variation(:,4)]')' variation(:,3)];
plot([1 2 4 8 15 20 25 30], variation2(:,1)','r');
plot([1 2 4 8 15 20 25 30], variation2(:,2)','g');
plot([1 2 4 8 15 20 25 30], variation2(:,3)','b');
plot([1 2 4 8 15 20 25 30], variation(:,2)','g--');
plot([1 2 4 8 15 20 25 30], variation(:,4)','g--');

plot([1 2 4 8 15 20 25 30], mean((variation2)')','k+-');

title('Average Read Noise vs Exposure');
xlabel('Exposure time (s)');
ylabel('Average Read Noise (pixel data)');
legend('red sensor', 'ave green sensor', 'blue sensor','green sensor 1','green sensor 2','average read noise', 'location', 'southeast');