2(a). For a 500 Hz square wave with unit amplitude, plot the approximation to it found by summing the first four terms of the Fourier series (that is, to the 7th harmonic) over the first period of the square wave [0, 2 ms].
Matlab Code:
clc
clear all
close all
t = 0:.01e-3:2e-3; %Time scale over 0 to 2ms
f = 500; %Frequency in Hz
n = [1:2:7]
for var = 1:length(n)
x(var,:) = (4/(pi*n(var)))*sin(2*pi*f*t*n(var));
end
x = sum(x); %Summing all sinusoids correspondis different
hormonics
plot(t*1e3,x) %plotting approximated square wave with first 4
hormonics
xlabel('time (in msec) ')
ylabel('Amplitude (in V)');
title('Approximated square wave over first 4 hormonics')
Output:
Get Answers For Free
Most questions answered within 1 hours.