31
ME 392 Adaptable Matlab Programing March 19, 2012 week 10 Joseph Vignola

ME 392 Adaptable Matlab Programing March 19, 2012 week 10

  • Upload
    erik

  • View
    44

  • Download
    0

Embed Size (px)

DESCRIPTION

ME 392 Adaptable Matlab Programing March 19, 2012 week 10. Joseph Vignola. Assignments . I would like to offer to everyone the extra help you might need to catch up. Assignment 5 is due March 26, one week from today Lab 3 is March 28, one week from the Wednesday. - PowerPoint PPT Presentation

Citation preview

Page 1: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

ME 392

Adaptable Matlab Programing March 19, 2012

week 10

Joseph Vignola

Page 2: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Assignments I would like to offer to everyone the extra help you might need to catch up.

Assignment 5 is due March 26, one week from todayLab 3 is March 28, one week from the Wednesday

Page 3: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

File Names, Title Pages & Information

Please use file names that I can search for

For example

“ME_392_assignment_5_smith_johnson.doc”

Please include information at the top of any document you give me. Most importantly:

NameDate What the document isLab partner

Page 4: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Zip File With Everything

Make a zip file with everything relevant to the assignment and make the file names easy to search for

For example

“ME_392_assignment_5_smith_johnson.zip”

Please include :

Main document MS WordDataM-files including subfunctionVI’s including subs

Page 5: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Logical Programing Logical programing is more important than the actual assignments

This is the only way you will get to the point where you can write complex programs that control a multi-faceted system

Flight-control system on a planeComplex measurement system like an ultrasound scannerPower plant

Page 6: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

Page 7: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

Things like making the time and frequency vectors

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

Page 8: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

Things like making the time and frequency vectors

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

Page 9: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

Things like making the time and frequency vectors

The sub-function is a separate m-file

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

Page 10: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

Things like making the time and frequency vectors

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

The sub-function is a separate m-fileand in this case just three line long

Page 11: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

The sub-function is a separate m-fileand in this case just three line long

As a general matter, variable names don’t need to be the same inside the sub-function as they are in the function that calls themSo you can have “t” in the subAnd “time” in the main program

Page 12: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

The way subs work is that the first input to the function in the main program goes to the first input of the function

So you can have “t” in the subAnd “time” in the main program

A = 1;fc = 1000;[freq,time] = freqtime(dt,num_of_samp);signal = A*sin(2*pi*fc*time) + noise(1,N);SIGNAL = fft(signal)*2/num_of_samp; zf(1) = figure(1);clfza(1) = axes;plot(time,signal);grid xlabel(…za(2) = axes;plot(freq,abs(SIGNAL));grid xlabel(…

Page 13: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

First input to first input

So you can have “t” in the subAnd “time” in the main program

A = 1;fc = 1000;[freq,time] = freqtime(dt,num_of_samp);signal = A*sin(2*pi*fc*time); SIGNAL = fft(signal)*2/num_of_samp; zf(1) = figure(1);clfza(1) = axes;plot(time,signal);grid xlabel(…za(2) = axes;plot(freq,abs(SIGNAL));grid xlabel(…

Page 14: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

First input to first input, second to the second

So you can have “t” in the subAnd “time” in the main program

A = 1;fc = 1000;[freq,time] = freqtime(dt,num_of_samp);signal = A*sin(2*pi*fc*time); SIGNAL = fft(signal)*2/num_of_samp; zf(1) = figure(1);clfza(1) = axes;plot(time,signal);grid xlabel(…za(2) = axes;plot(freq,abs(SIGNAL));grid xlabel(…

Page 15: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

First output to first output

So you can have “t” in the subAnd “time” in the main program

A = 1;fc = 1000;[freq,time] = freqtime(dt,num_of_samp);signal = A*sin(2*pi*fc*time); SIGNAL = fft(signal)*2/num_of_samp; zf(1) = figure(1);clfza(1) = axes;plot(time,signal);grid xlabel(…za(2) = axes;plot(freq,abs(SIGNAL));grid xlabel(…

Page 16: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code

function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);

First output to first output, second to the second

So you can have “t” in the subAnd “time” in the main program

A = 1;fc = 1000;[freq,time] = freqtime(dt,num_of_samp);signal = A*sin(2*pi*fc*time); SIGNAL = fft(signal)*2/num_of_samp; zf(1) = figure(1);clfza(1) = axes;plot(time,signal);grid xlabel(…za(2) = axes;plot(freq,abs(SIGNAL));grid xlabel(…

Page 17: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code Lets you use code that you know works

You will be making time and frequency vectors for all the remaining labs and assignments

Page 18: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code Lets you use code that you know works

You will be making time and frequency vectors for all the remaining labs and assignments

You needed to scale, AC couple, integrate and plot accelerometer data for the last. There is no need to re-write all that

Page 19: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code Lets you use code that you know worksSimplifies the main program

This is not important if your code is only a few lines long

Page 20: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code Lets you use code that you know worksSimplifies the main program

This is not important if your code is only a few lines long but if you are complex having discreet pieces make for much easier debugging

Page 21: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Sub-functionsSub-functions do several things for you

Lets you quickly reuse code Lets you use code that you know worksSimplifies the main program

This is not important if your code is only a few lines long but if you are complex having discreet pieces make for much easier debugging

It is much easier on Therese or me to help if your code is simple to follow

Page 22: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Matlab PathFunctions look just like variables

So when you have a used defined function will first look for it as a variable

Then Matlab will look in the current directory (the one listed above the command window)

The Matlab will look, in order, in the directories in the path.

Page 23: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Setting the Matlab PathFunctions look just like variables

So when you have a used defined function will first look for it as a variable

Then Matlab will look in the current directory (the one listed above the command window)

The Matlab will look, in order, in the directories in the path.

Page 24: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Gain MeasurementAssignment 5 asks you to find a relationship between the input and the output for a shaker.

The relationship would be a measure of displacement of the shaker as a function of input voltage at several frequencies

The amplifier increases the voltage that comes out of the BNC 2120 box.

Page 25: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Gain MeasurementAssignment 5 asks you to find a relationship between the input and the output for a shaker. The amplifier input should not exceed about 0.250 volts and the frequencies should be in the audio band 20-20,000 Hz

Page 26: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Gain MeasurementAssignment 5 asks you to find a relationship between the input and the output for a shaker. The amplifier input should not exceed about 0.250 volts and the frequencies should be in the audio band 20-20,000 Hz

All the power amps are a little different.

Page 27: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Gain MeasurementAssignment 5 asks you to find a relationship between the input and the output for a shaker. The amplifier input should not exceed about 0.250 volts and the frequencies should be in the audio band 20-20,000 Hz

All the power amps are a little different.

Gain should be about 10

Page 28: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Gain MeasurementAssignment 5 asks you to find a relationship between the input and the output for a shaker. The amplifier input should not exceed about 0.250 volts and the frequencies should be in the audio band 20-20,000 Hz

All the power amps are a little different.

Gain should be about 10 (dimensionless)

Page 29: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Look at the signalsIt is very important to look at the signals as you work

Page 30: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Look at the signalsIt is very important to look at the signals as you work

Be sure the power amp is at full gain

Page 31: ME 392 Adaptable Matlab Programing  March  19, 2012 week 10

Look at the signalsIt is very important to look at the signals as you work

Be sure the power amp is at full gain

Look at the wiringBe sure the input selector is set to the something you are connected to