clc, clear, close all

video = VideoReader('12-39-09_moving_30fps_lowres_32_out-ideal-from-0.83333-to-2.0833-alpha-80-level-2-chromAtn-1.avi');
signal = zeros(1,video.NumFrames);
time_scale = 30/video.NumFrames;
time_axis = (1:1:video.NumFrames)*time_scale*60;

for i = 1:video.NumFrames
    iFrame = readFrame(video);
    R_signal(i) = sum(sum(iFrame(:,:,1)))/(size(iFrame(:,:,1),1)*size(iFrame(:,:,1),2));%iFrame(10,10,1); %R
    G_signal(i) = sum(sum(iFrame(:,:,2)))/(size(iFrame(:,:,2),1)*size(iFrame(:,:,2),2));%iFrame(10,10,2); %G
    B_signal(i) = sum(sum(iFrame(:,:,3)))/(size(iFrame(:,:,3),1)*size(iFrame(:,:,3),2));%iFrame(10,10,3); %B
end

freqR = fft(R_signal);
freqG = fft(G_signal);
freqB = fft(B_signal);
freq = freqR+freqG+freqG;
% freq = fft(B_signal);
freq(1) = 0;
bar(time_axis,abs(real(freq))./video.NumFrames);
xlabel('BPM')
