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

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

Save
View full document
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
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
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:

Phasor Representation of HarmonicsMatrix ExercisesSynthesis of WaveformsTest WaveformsComplex Waveform 1Complex Waveform 2ECE 300Representing Complex Signals in MATLAB - Lab 5ECE 300 Signals and SystemsIn this laboratory, you will learn how to write functions in MATLAB that will makethe study of signals and systems much easier. This will help us to use Matlab tostudy 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 sinusoidalwaveforms of the form:x(t)  Acos(2f0t ) Re Aejej2f0t (1)In this lab, we will synthesize more complex waveforms composed of sums ofsinusoidal signals, each with a different frequency (fk)NktfjkNkkkkkeZtfAtx121Re)2cos()((2)where Zk = Ak ejk is the complex phasor amplitude associated with frequency fk.Phasor Representation of HarmonicsThere is an important special case where x(t) is the sum of N cosine waveswhose 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 x(t)  Akcos(2kf0t k)k1NRe Zkej2kf0tk1NThis particular signal x(t) is periodic with period T0 = 1/f0. The frequency f0 iscalled the fundamental frequency, and T0 is called the fundamental period.BAF 1 of 6 6 January 2002ECE 300Prelab 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 theattached “MATLAB Programming Tips” and then do the following. (a) Find the mistake(s) in the following function and test it to verify itsperformance: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 periody=abs(2*pi*f*t);(b) Find the mistake(s) in the following function and test it to verify itsperformance: 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 afor 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 2002ECE 300% x=the input vector that comprises % the identical columns of Z%ncol=the number of desired columns%x=x(:); % this turns the input % vector x into a % column vectorfor k=1:ncol Z(:,k)=x;end(d) Write a function that performs the same task as the following without using afor 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 endendMATLAB Hint: The MATLAB logical operators may be helpful in completing thisexercise. Use help to understand what these commands do. Equipment:BAF 3 of 6 6 January 2002ECE 300Computer with MATLABProcedures:Matrix ExercisesRead 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] % creates a vector t with elements incrementing from % 0 to 2 by 0.25t=[0:0.25:2]; % the “;” suppresses the printing of the resultsy=0.5*t % MATLAB uses “implicit definition” - y is automatically made into% a vector with the same dimensions as tz=cos(y) % this even works for a function - z(1)=cos(y(1)), etc.f=[1 2 3] % create a vector of frequenciesz=f*y % ERROR! - you can’t do this with vectors, right?g=f' % the “ ‘ “ notation gives the transpose of the matrixh=f’ * y % what is the result?b=sum(h) % replaces columns with the sum of the elements of the column - so% b has the same dimension as y (or t)! cc=sum(cos(f’*t)) % this sums up cosines, each having its own freq - cc=cos(f(1)*t)+% cos(f(2)*t)+ cos(f(3)*t)a=[15 10 5] % create a vector of amplitudes corresponding to the frequenciescc=a*cos(f’*t) % creates the summation of three sinusoids with amplitudes and % frequencies Synthesis of WaveformsWrite an M-file that will synthesize a waveform in the form of Equation (2). Write the functionwithout 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 sumcosshould be real-valued!In order to use this M-file to synthesize periodic waveforms, you would simply choose the entries in thefrequency vector to be integer multiples of the desired fundamental frequency. Try the following test andplot the result.1/14/2019 4 of 6ECE 300xx=sumcos([20 40 60 80],[1 -1 1 -1],200,1.5);Test WaveformsEach 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 signalto observe its characteristic shape. If you computer can play sounds, change the fundamentalto 1 kHz listen to 0.8 secs. of the signal using sound(x, fs).Complex Waveform 1Try your M-file with the


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 2 2 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?