DOC PREVIEW
Rose-Hulman ECE 300 - ECE 300 Lab 5

This preview shows page 1-2 out of 6 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ECE 300 Representing Complex Signals in MATLAB Lab 5 ECE 300 Signals and Systems In this laboratory you will learn how to write functions in MATLAB that will make the study of signals and systems much easier This will help us to use Matlab to study the spectrum of a signal using the FFT later Objectives This laboratory project has two objectives 1 Learn how to write functions in MATLAB and 2 Write a function that will sum several cosines Background We have spent a lot of time learning about the properties of sinusoidal waveforms of the form x t Acos 2 f0t Re Ae j e j2 f0 t 1 In this lab we will synthesize more complex waveforms composed of sums of sinusoidal signals each with a different frequency fk N x t Ak cos 2 f k t k k 1 2 N Re Z k e j 2 f k t k 1 where Zk Ak ej k is the complex phasor amplitude associated with frequency fk Phasor Representation of Harmonics There is an important special case where x t is the sum of N cosine waves whose frequencies fk are all multiples of one basic frequency f0 fk k f0 Harmonic Frequencies The sum of N cosine waves given by Equation 2 becomes N N x t Ak cos 2 kf0 t k Re Zk e j2 kf0t k 1 k 1 This particular signal x t is periodic with period T0 1 f0 The frequency f0 is called the fundamental frequency and T0 is called the fundamental period BAF 1 of 6 6 January 2002 ECE 300 Prelab Exercises If you haven t been through the MATLAB introduction exercises MATLAB Intro on the Web Page do those exercises for the prelab The goal is to give you a jump start in writing functions in MATLAB Read the attached MATLAB Programming Tips and then do the following a Find the mistake s in the following function and test it to verify its performance function x cosgen f dur COSGEN Function to generate a cosine wave usage x cosgen f dur f desired frequency dur duration of the waveform in seconds t 0 1 20 f dur gives 20 samples per period y abs 2 pi f t b Find the mistake s in the following function and test it to verify its performance function sum prod sumprod x1 x2 SUMPROD Function to add and multiply two complex numbers usage sum prod sumprod x1 x2 x1 a complex number x2 another complex number sum sum of x1 and x2 prod product of x1 and x2 sum z1 z2 prod z1 z2 c Write a function that performs the same task as the following without using a for loop and then test the function function Z expand x ncol EXPAND Function to generate a matrix Z with identical columns equal to an input vector x usage Z expand x ncol BAF 2 of 6 6 January 2002 ECE 300 x the input vector that comprises ncol the number of desired columns x x this turns the input vector x into a column vector for k 1 ncol Z k x end the identical columns of Z d Write a function that performs the same task as the following without using a for loop function Z replacez A REPLACEZ Function that replaces the positive elements of a matrix with 1 usage Z replacez A A input matrix whose positive elements are to be replaced with 1 M N size A for i 1 M for j 1 N if A i j 0 Z i j 1 else Z i j A i j end end end MATLAB Hint The MATLAB logical operators may be helpful in completing this exercise Use help to understand what these commands do Equipment BAF 3 of 6 6 January 2002 ECE 300 Computer with MATLAB Procedures Matrix Exercises Read the MATLAB Program Tips document and understand what is being done in each section Start MATLAB and click the cursor in the command window where there is a command prompt Enter the following commands not the comments and observe the results t 0 0 25 2 t 0 0 25 2 y 0 5 t z cos y f 1 2 3 z f y g f h f y b sum h cc sum cos f t a 15 10 5 cc a cos f t creates a vector t with elements incrementing from 0 to 2 by 0 25 the suppresses the printing of the results MATLAB uses implicit definition y is automatically made into a vector with the same dimensions as t this even works for a function z 1 cos y 1 etc create a vector of frequencies ERROR you can t do this with vectors right the notation gives the transpose of the matrix what is the result replaces columns with the sum of the elements of the column so b has the same dimension as y or t this sums up cosines each having its own freq cc cos f 1 t cos f 2 t cos f 3 t create a vector of amplitudes corresponding to the frequencies creates the summation of three sinusoids with amplitudes and frequencies Synthesis of Waveforms Write an M file that will synthesize a waveform in the form of Equation 2 Write the function without using for loops The first few statements of the M file should look like function x sumcos f Z fs dur SUMCOS Function to synthesize a sum of cosine waves usage x sumcos f Z fs dur f vector of frequencies could be negative or positive Z vector of complex phasors Amp e j phase fs the sampling rate in Hz dur total time duration of signal Note f and Z must be the same length Z 1 corresponds to frequency f 1 Z 2 corresponds to frequency f 2 etc NOTE The sumcos routine is to implement equation 2 and thus the vector returned from sumcos should be real valued In order to use this M file to synthesize periodic waveforms you would simply choose the entries in the frequency vector to be integer multiples of the desired fundamental frequency Try the following test and plot the result 1 14 2019 4 of 6 ECE 300 xx sumcos 20 40 60 80 1 1 1 1 200 1 5 Test Waveforms Each of the following waveforms can be synthesized with a simple call to the function sumcos Create a main script file to perform the following examples Plot a short section of the signal to observe its characteristic shape If you computer can play sounds change the fundamental to 1 kHz listen to 0 8 secs of the signal using sound x fs Complex Waveform 1 Try your M file with the fundamental f0 25 Hz fk k f0 and j Zk k 0 k an odd integer 3 k an even integer Specify the duration to get three periods of the waveform Make plots for three different cases N 5 10 and 25 where N is the number of cosines Use a three panel …


View Full Document

Rose-Hulman ECE 300 - ECE 300 Lab 5

Documents in this Course
Exam 2

Exam 2

8 pages

Load more
Download ECE 300 Lab 5
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ECE 300 Lab 5 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ECE 300 Lab 5 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?