Conflicts due to poor backup

This commit is contained in:
Maryne DEY 2023-02-16 12:20:00 +01:00
parent 58b3da59b0
commit 7f8cd87cbb
1 changed files with 0 additions and 65 deletions

65
FFT.m
View File

@ -1,65 +0,0 @@
%%%%%%%%%%%%%%%%%%%%%
% Script task: Normalize RGB data and plot FFT using the power spectra
%
% Input : RGB_data.csv -> average RGB values of each image
%
% Output : Fast Fourier Transform of X(t): a graph representing the Single-Sided Amplitude Spectrum of X(t)
%
% Author: Maryne DEY (maryne.dey@ecam.fr)
% Date: 07/02/2023
%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%To be able to extract from external format (excel)
pkg load io
%Normalization of the data
data = csvread('RGB_database/RGB_data.csv');
standard_deviation = std(data);
mean_value = mean(data);
for i = 1:size(data,1)
normalized_data_G(i,1) = (data(i,2)-mean_value(2))/standard_deviation(2); %%2 and not 1 because green is the 2nd color
endfor
%Input characteristics
Fs = 970/32; % Sampling frequency = 970 images in 32 seconds
T = 1/Fs; % Sampling period
L = 970; % Length of signal = 32 seconds
t = (0:L-1)*T; % Time vector
X = normalized_data_G;
%Plot of the RGB data in the time domain
plot(t(1:970),X(1:970))
title("Signal")
xlabel("t (milliseconds)")
ylabel("X(t)")
%Finding power spectra P2 and P1
Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
% Finding boudaries
start = find(f==0.75);
stop = find(f==4);
P1_graph = P1(start:stop);
f_graph = f(start:stop);
%Graph of FFT in function of the frequency
plot(f_graph,P1_graph)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
%Extracting the heart rate
[heart_rate_Hz, index] = max(P1_graph);
corresponding_frequency = f_graph(index);
heart_rate_bpm = corresponding_frequency*60;
fprintf("Your heart rate is about %d bpm.\n", heart_rate_bpm)