% Amplitude Distortion

clc             % clear the command window
clear           % clear all variables
close all       % close any existing windows
format compact	% prevent extra blank lines in the output

t = 0 : 0.01 : 2;
n = 1 : 50;

B(n) = 4 ./(pi*(2*n-1)) .* exp(-0.1*(2*n-1));
C(n) = 4 ./(pi*(2*n-1)) .* (1 - exp(-(2*n-1)));

sum = 0;
for n = 1 : 50
    sum = sum + B(n)*sin((2*n-1)*2*pi*t);
end
F_high = sum;
sum = 0;
for n = 1 : 50
    sum = sum + C(n)*sin((2*n-1)*2*pi*t);
end
F_low = sum;

display ('F(t) = sin(a*t) + sin(b*t)');

% Plot square wave with high-frequency attenuation
plot (t, F_high)
title ('high-frequency components attentuated');
xlabel('t');
ylabel('F_high(t)');

% Plot square wave with high-frequency attenuation
figure      % open new figure window (to prevent previous from being lost)
plot (t, F_low)
title ('low-frequency components attentuated');
xlabel('t');
ylabel('F_low(t)');

disp 'Hit Enter to close all windows and quit'
pause
close all