Question
Utilize the MATLAB implementation of the Fourier Series approximation of an even square wave (that you developed in Module 2), to develop a function M-file
Utilize the MATLAB implementation of the Fourier Series approximation of an even square wave (that you developed in Module 2), to develop a function M-file called sq_wave_fourier_fn_LastName.m. The input arguments are to be freq, time, and N; where freq = square wave frequency in Hz, time = vector of time points, N = number of terms in the Fourier Series approximation. The output of the function is the approximation of the square wave. Then create a driver program called sq_wave_driver_LastName.m that generates three different approximations (for N = 3, 9 and 29) of a 1 Hz square wave and plots them on three separate subplots. Obviously your driver program should call your function m-file to generate the approximations.
clc tic N=10; f = 1; w = 2*pi*f; for n=1:1:N if rem(n,2)==0 a(n)=0 else if rem(n-1,4)< 1 a(n)=4/n*pi; else a(n)=-4/n*pi; end end end n=3; k = 0; for t = -2:0.001:2 k = k + 1; f(k) = 0; % Loop over the total number of terms in the approximation for n = 1:N, f(k) = f(k) + a(n)*cos(omega.*n*t) time(k) = t; end end % End loop over time toc % Plot the results plot(time,f) title(strcat('Fourier Series Approximation with N = ',num2str(N),' terms')) ylabel('function value') xlabel('time (seconds)')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started