% Plot of the Fourier sine series for a ramp function
% Barukyah Shaparenko and John M. Cimbala

clear all
close all

del_t = 0.02; % s
omega = 2*pi; % rad/s

% Fourier series coefficients
a_1 = -25/pi;
a_2 = -25/(2*pi);

t = [0:del_t:2]';
f = 12.5 + a_1*sin(omega*t) + a_2*sin(2*omega*t);

% Exact ramp function (data created for the plot):
ramp = [0 1 1 2; 0 25 0 25]';

scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)/4 scrsz(4)*1/8 scrsz(3)/2 scrsz(4)*3/4])

subplot(2,1,1)
hold on;
plot(ramp(:,1),ramp(:,2),'b-','LineWidth',2)
grid on;
xlabel('\bf\itt \rm\bf(s)','FontSize',10)
ylabel('\bf\itf \rm\bf(\itt \rm\bf)','FontSize',10)
hold off;

subplot(2,1,2)
hold on;
plot(ramp(:,1),ramp(:,2),'b-','LineWidth',2)
plot(t,f,'r--','LineWidth',2)
grid on;
xlabel('\bf\itt \rm\bf(s)','FontSize',10)
ylabel('\bf\itf \rm\bf(\itt \rm\bf)','FontSize',10)
legend('Exact','Fourier series approximation','Location','SouthOutside','Orientation','Horizontal')
%xlim([0 10*T])
%ylim([C-A C+A])
%pbaspect([2 1 1])
%legend('analog signal','discrete signal','Location','SouthOutside','Orientation','Horizontal')
hold off;

site = '"http://www.mne.psu.edu/me345/Lectures/Fourier_ramp_2_coeffs.xls"';
title = 'Excel file';
fprintf(['\nView corresponding <a href = ' site '>' title '</a>\n']);
