% Richard Duncan
% EE3133
% Assignment 4: Fourier Series, question I
% 2/13/97
%
% - Construct a signal that is the sum of the following:
%
%   x(t) = 0.5 sin(2*PI*1000*t + PI/3) + 0.25 cos(2*PI*1500t + PI/4)
% f1 = 1000; T1 = 0.001; f2 = 1500; T2 = 0.0006666
%
%   2 * (0.001) = 3 * (0.00066666); T0 = 0.002, f0 = 500 Hz

T = 0.002;
t0 = 0;
w0 = 500 * 2 * pi;
num = 4;

syms t x x1 x2;

x1 = sin(2 * pi * 1000 * t + pi/3) /2;
x2 = cos(2 * pi * 1500 * t + pi/4) /4;
x = x1 + x2;

%   Using whatever tools are available to you in Matlab, compute the
%   Fourier series of this signal. Explain the result.

% a0 = int(x,t0,T+t0) /T;

for n = 0:(num-1)
   a(n+1) = (2/T) * eval(int(x * cos(n*w0*t),t0,T+t0));
   b(n+1) = (2/T) * eval(int(x * sin(n*w0*t),t0,T+t0));
end

% Explanation of Fourier coefficients for part I
%
% clearly, the first space in each vector (a1 & b1) will be zero, as
% it corresponds to the fundamental frequency of 500Hz, which does not
% exist in this wave. The a2,b2 will correspond to the 1000 Hz wave, aka
% x1. The differences in magnitude correspond to the time shift of
% pi/3. The n=3 coefficients will correspond to the cosine wave, aka x2,
% time shifted by pi/4.

for n = 0:(num-1)
   at(n+1) = cos(n*w0*t);
   bt(n+1) = sin(n*w0*t);
end

% multiply the two vectors together, element by element
%
% Note: I first tried xt = a0 + a * transpose(at) + b * transpose(bt)
%       but it didn't work. The assumption is that that the mixed mode 
%       of symbolic/numeric data caused problems

xt = 0;
for n = 1:num
   xt = xt + a(n) * at(n) + b(n) * bt(n);
end

t = [0:.00001:.01];

close
plot(t,eval(xt),'r')
hold
plot(t,eval(x1),'g')

% end of file
%



