clear;clc;close all;

set(0,'defaulttextinterpreter','Latex');

Fs = 500;
Ts = 1/Fs;
dt=0:Ts:0.5-Ts;

f1=10;f2=35;f3=50;f6=20;f7=90;

y1=10*sin(2*pi*f1*dt);
y2=5*sin(2*pi*f2*dt);
y3=3*sin(2*pi*f3*dt);
y4=8*sin(2*pi*f6*dt);
y5=13*sin(2*pi*f7*dt);

y6 = y1 + y2 +y3  +y4 +y5;

figure(1); %Obr 2.1
plot(dt,y6,'k','Linewidth',2);
xlabel('t[s]')
set(gca,'FontSize',25)

N = length(y6);
N2 = 2*2^nextpow2(N);

ff = fft(y6,N2);
fff = ff(1:N2/2);
xff=Fs*(0:N2/2-1)/N2;

figure(2); %Obr 2.2
plot(xff(1:end),abs(fff(1:end)),'k','Linewidth',2);
xlabel('f[Hz]');
ylh = get(gca,'ylabel');
gyl = get(ylh);                                                        
ylp = get(ylh, 'Position');
set(ylh, 'Rotation',0, 'Position',ylp, 'VerticalAlignment','middle', 'HorizontalAlignment','right')
ylabel('$\left|X_k\right|$');
set(gca,'FontSize',25)

figure(3) %Obr 2.3
plot(xff(1:end),180/pi*angle(fff(1:end)),'k','Linewidth',2);
xlabel('f[Hz]');
ylh = get(gca,'ylabel');
gyl = get(ylh);                                                        
ylp = get(ylh, 'Position');
set(ylh, 'Rotation',0, 'Position',ylp, 'VerticalAlignment','middle', 'HorizontalAlignment','right')
ylabel('$\mbox{Arg}(X_k)$');
set(gca,'FontSize',25)