diff --git a/octave/PPG.m b/octave/PPG.m new file mode 100644 index 0000000..b241e67 --- /dev/null +++ b/octave/PPG.m @@ -0,0 +1,35 @@ +% First we have to extract the values of red(R), green(G) and blue(B) from the txt file. +fileID = fopen("listRGB.txt"); % Opening the txt file +M = textscan(fileID, "[[%f, %f, %f]]"); % Extracting the values +fclose(fileID); % Closing the file +R = M{1}; +G = M{2}; +B = M{3}; + +% Then we normalize the different RGB vectors but substracting the mean value and divide by the standard deviation. +Normal_R = (R - mean(R)) ./ std(R); +Normal_G = (G - mean(G)) ./ std(G); +Normal_B = (B - mean(B)) ./ std(B); + +% We now use the fastICA functions in order to obtain 3 channels of 450 samples each. +[icasig, A, W] = fastica([Normal_R'; Normal_G'; Normal_B']); + +% Here we compute the magnitude of the fast Fourrier's transform. +PPG_spectrum_R = abs(fft(Normal_R)); +PPG_spectrum_G = abs(fft(Normal_G)); +PPG_spectrum_B = abs(fft(Normal_B)); + +% This line of code is for computing the frequency of each samples. +f = [0:450]./450*15; + +% Then we find the maximum of each channels and by knowing the index of it, we find the corresponding frequency. +[value_R, idx_R] = max(PPG_spectrum_R); +heart_rate_freq_R = f(idx_R); +[value_G, idx_G] = max(PPG_spectrum_G); +heart_rate_freq_G = f(idx_G); +[value_B, idx_B] = max(PPG_spectrum_B); +heart_rate_freq_B = f(idx_B); + +% Finally, we display the BPM by multiplying the frequency by 60 and find the maximum of each channels. +disp(max([heart_rate_freq_R*60,heart_rate_freq_G*60,heart_rate_freq_B*60])) +