diff --git a/FFT.m b/FFT.m new file mode 100644 index 0000000..05be1df --- /dev/null +++ b/FFT.m @@ -0,0 +1,47 @@ +%%%%%%%%%%%%%%%%%%%%% +% 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 + +pkg load io %% to be able to extract from external format (excel) + +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 + +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(t(1:970),X(1:970)) +title("Signal") +xlabel("t (milliseconds)") +ylabel("X(t)") + +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 + +plot(f(25:end),P1(25:end)) +title("Single-Sided Amplitude Spectrum of X(t)") +xlabel("f (Hz)") +ylabel("|P1(f)|") \ No newline at end of file