310 likes | 458 Views
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.
E N D
ME 392Adaptable Matlab Programing March 19, 2012week 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
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: Name Date What the document is Lab partner
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 Word Data M-files including subfunction VI’s including subs
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 plane Complex measurement system like an ultrasound scanner Power plant
Sub-functions Sub-functions do several things for you Lets you quickly reuse code
Sub-functions Sub-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);
Sub-functions Sub-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);
Sub-functions Sub-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);
Sub-functions Sub-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 and in this case just three line long function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-functions do several things for you Lets you quickly reuse code 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 them The sub-function is a separate m-file and in this case just three line long So you can have “t” in the sub And “time” in the main program function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-functions do several things for you Lets you quickly reuse code The way subs work is that the first input to the function in the main program goes to the first input of the function 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);clf za(1) = axes; plot(time,signal);grid xlabel(… za(2) = axes; plot(freq,abs(SIGNAL));grid xlabel(… So you can have “t” in the sub And “time” in the main program function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-functions do several things for you Lets you quickly reuse code First input to first input 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);clf za(1) = axes; plot(time,signal);grid xlabel(… za(2) = axes; plot(freq,abs(SIGNAL));grid xlabel(… So you can have “t” in the sub And “time” in the main program function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-functions do several things for you Lets you quickly reuse code First input to first input, second to the second 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);clf za(1) = axes; plot(time,signal);grid xlabel(… za(2) = axes; plot(freq,abs(SIGNAL));grid xlabel(… So you can have “t” in the sub And “time” in the main program function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-functions do several things for you Lets you quickly reuse code First output to first output 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);clf za(1) = axes; plot(time,signal);grid xlabel(… za(2) = axes; plot(freq,abs(SIGNAL));grid xlabel(… So you can have “t” in the sub And “time” in the main program function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-functions do several things for you Lets you quickly reuse code First output to first output, second to the second 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);clf za(1) = axes; plot(time,signal);grid xlabel(… za(2) = axes; plot(freq,abs(SIGNAL));grid xlabel(… So you can have “t” in the sub And “time” in the main program function [f,t] = freqtime(si,N) t = [0:N-1]’*si; f = t/(si*si*N);
Sub-functions Sub-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
Sub-functions Sub-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
Sub-functions Sub-functions do several things for you Lets you quickly reuse code Lets you use code that you know works Simplifies the main program This is not important if your code is only a few lines long
Sub-functions Sub-functions do several things for you Lets you quickly reuse code Lets you use code that you know works Simplifies 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
Sub-functions Sub-functions do several things for you Lets you quickly reuse code Lets you use code that you know works Simplifies 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
Matlab Path Functions 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.
Setting the Matlab Path Functions 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.
Gain Measurement Assignment 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.
Gain Measurement Assignment 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
Gain Measurement Assignment 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 Measurement Assignment 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
Gain Measurement Assignment 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)
Look at the signals It is very important to look at the signals as you work
Look at the signals It is very important to look at the signals as you work Be sure the power amp is at full gain
Look at the signals It is very important to look at the signals as you work Be sure the power amp is at full gain Look at the wiring Be sure the input selector is set to the something you are connected to