%=========================================================
%  Program  : LS_FFT.m
%  Author   : L. Sevgi
%  Date     : May 2006
%  Purpose  : To take the FFT of two sinuzoids
%=========================================================
clear all;
close all;
clc;

f1=input ('Frequency of the first sinuzoid [Hz] : ');
A1=1; %input ('Amplitude of the first sinuzoid [] : ');
f2=input ('Frequency of the second sinuzoid [Hz] : ');
A2=0.5; %input ('Amplitude of the second sinuzoid [] : ');
dt=input ('Time sampling interval (Delta_t) [s] : ');
T=input ('Time duration (T) [s] : ');

N=floor(T/dt);
df=1/T;
fmax=1/(2*dt);

for n=1:N
    t=(n-1)*dt;  
    tt(n)=(n-1)*dt;
    x(n)=A1*sin(2*pi*f1*t)+A2*exp(j*2*pi*f2*t);
%   x(n)=A1*exp(-j*2*pi*f1*t)+A2*sin(2*pi*f2*t);
    f(n)=-fmax+2*(n-1)*fmax/(N-1);
end

%%%%%%%%%%%%%%%%% APPLY FFT %%%%%%%%%%%%%%%%%%%%%
 xx=fftshift(x); %swaps the left and right halves
 X=fft(x);
 XX=fftshift(X); %swaps the left and right halves
% XX=fft(x);

% -------- Plot ---------
subplot(2,1,1)
hold;
plot(tt,x);
grid;
xlabel('t (seconds)')
ylabel('x(t)');
title('x(t) Fonction');

subplot(2,1,2)
hold;
plot(f,abs(XX))
grid;
xlabel('f (Hz)')
ylabel('X(f)');
title('Frequency response of x(t)');
%
% ------------------ END ---------------------