This function approximates a square wave by swimming a series of sinusoidal func
ID: 3109724 • Letter: T
Question
This function approximates a square wave by swimming a series of sinusoidal functions of various frequencies and amplitudes. X_square (t) = sigma^infinity_k=1 sin(omega t(2k - 1))/2k - 1 In MATLAB write a function that allows the user to choose the number of terms used to approximate the square wave, i.e. input the value of k. Your function should plot the resulting square wave, show the value used for k in the title (dynamic), and plot the FFT all on the same page. Label the square wave and FFT plots. SET omega = 1 in the equation for this exercise. Additional low level plot commands you may need: xlabel('Time period') % label the x-axis with "Time period" ylabel('Amplitude') % label the y-axis with "Amplitude" title ('sine wave') %title the plot with "sine wave"Explanation / Answer
Matlab codes
Clc;
Clear all;
w=1;
t=linspace(0,1,10000);
k=('input value of k':);
sum=0;
For i=1:k
x=sum+sum(sin(w*t*(2*i-1))/(2*i-1));
i=i+1;
sum=x;
End
plot(t,x);
xlabel('Time Period');
ylabel('Amplitude');
title('Sine Wave');
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.