Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please show all matlab code. Thanks for the help 4) Scripts and Functions: Any collection of Matlab commands can be gathered to- gether as a

Please show all matlab code. Thanks for the help

image text in transcribedimage text in transcribed

4) Scripts and Functions: Any collection of Matlab commands can be gathered to- gether as a script, saved in an m-file. For instance save the following commands in a text file called plotit.m numhar = 5; numpoints = 300; t = linspace(0,2*pi,numpoints); y = zeros(1, numpoints); for ii = 1:numhar y = y + ((-1)^(ii+1))*(1/(2*ii-1)) *cos((2 *ii-1)*t); end plot(t,y) title( 'Harmonic decomposition of a square wave') You can then run this straight from Matlab (just type plotit) to build a square wave from its harmonics and plot it. The formulae for the harmonic series coefficients comes from the Fourier Series expansion (verify that). Note that this is a script in that all the variables exist in the workspace. You can also write subroutines, which use local variables. Type help function to see the syntax for doing this. Carry out the following programming tasks: i) Write a function from the above script to generate and plot a square wave from its har- monics. The inputs should include the number of harmonics and number of points. The outputs should include the time and amplitude vectors for the square wave. Plot the wave for various values. Can you see Gibb's phenomenon when the number of harmonics is large? ii) Write a function which gives back the sum of the squares of the absolute values of the elements of a matrix, i.e., it evaluates the function n m f = 10:51 i=1 j=1 for any n x m matrix a. Test your routine on the matrices a, b, c from question 1)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions