% Example of computing approximation function by using sin(x) and cos(x)
% Introduction to Digital Communications
% Written by Vitaly Skachek
%
A = 1; % amplitude of the signal
f = 1/(2*pi); % frequency is 1 over the period of the function
t = -6:0.05:6; % sample points
num_points = length(t); % number of sample points
num_terms_vector = [5, 15, 50, 300]; % number of terms in the series
for num_terms = num_terms_vector,
s = ones(1, num_points)*A/2; % computing a_0 coefficient
for i = 1:1:num_points,
sum = 0;
for n = 1:2:num_terms,
sum += (2*A/(n*pi))*sin(pi*n/2)*cos(2*pi*n*f*t(i));
end;
s(i) += sum;
end;
figure;
plot(t,s);
end;