clear all; close all; clc

N=1024; % num sinusoid
L=pi;
dx=2*L/(N-1); % delta x
x=-L:dx:L; % range is -pi to pi 

f1=3;
func1=sin(2*pi*f1*x); % pure sine wave 3Hz as freq

f2=2;
func2=sin(2*pi*f2*x); % pure sine wave 2Hz as freq
figure;
plot(x,func1,'b-')
hold on
plot(x,0.5*func2,'r-')
title('Continuous sinusoidal signal')
xlabel('Time(s)');
ylabel('Amplitude');

func3=1*func1+0.5*func2;
figure;
plot(x,func3)
xlim([-4 4])
ylim([-1.5 1.5])

figure;
%% simulating the singal with 20 sinusoids
A0 = sum(func3.*ones(size(x)))*dx/pi;
fFS = A0/2;
CC = jet(20);
for k=1:20
    v=k*2*pi;
    A(k)=sum(func3.*cos(v*x))*dx/pi; % inner product
    B(k)=sum(func3.*sin(v*x))*dx/pi; % inner product
    fFS = fFS + A(k)*cos(v*x) + B(k)*sin(v*x);
    plot(x, fFS, '-', 'Color', CC(k,:), 'LineWidth', 2)
    pause(1)
end

figure;
stem(1:20, A, 'b*-')
hold on;
stem(1:20, B, 'r*-')


%min_freq_range = 0.0;
%max_freq_range = 10.0;
%for freq=min_freq_range:0.1:max_freq_range
%    exp(-2*pi*i*freq)
%end





