% This code is for Home exercise 3 of Advances in New Energy Technologies course (Spring 2022). % All you need to do is to add correct file, i.e. name on line 6 (and change the label of y-axis on line 18). % Do not change anything else from the code unless you know what you are doing. % The data file has to be in the same folder where the code file is. data = load('data1.txt'); % Loads the data file. N = length(data); % Number of data points f = zeros(length(data), 1); % Initializing a vector for frequencies CL = zeros(length(data), 1); % Initializing a vector for cycle lengths t = 1; % Time step between measurement points (1h) h = 1:length(data); % Time moments of the measurement points figure(1) % These lines plot the data as a function of time plot(h, data) grid on; xlabel('Time (h)') % Label of x-axis is the same for all datasets ylabel('Solar radiation (W/m^2)') % Label of y-axis can be changed here ft = fft(data); % This function performs a Fourier transform to the data A = abs(ft); % Calculates the amplitudes for k = 1:N % This loop calculates respective cycle length for each Ak f(k) = (k - 1) / (N * t); CL(k) = 1 / f(k); end figure(2) % These lines plot the amplitude of the Fourier transform plot(CL, A, '.-') % as a function of respective cycle length. xlabel('Cycle length (h)') ylabel('Amplitude') grid on;