Lab 4 due 12/4
Before we start with the lab, please have a good look at the lab report assignment. Make sure to understand all the objectives of the assignment to generate all the results you need for your report.
Read Chapter 6 of the Lab Textbook before completing this lab.
You are required to write a short laboratory report to present and discuss their results. You can assume that the reader is familiar with the experiment; focus on a clear description of your results instead of recounting the laboratory procedure. The report should be logically organized and include titles, headings and subheadings to organize the report. The report should present and discuss the following topics:
1. Time-Averaging
Present the results of your time averaging MATLAB script to convert the 1 second of voltage data to a single average voltage.
Present at least one figure to illustrate the 1 second of data at 100 Hz and the resulting average value.
You should also calculate the standard deviation of this 1 second of data. What does the standard deviation suggest about the variability in your measurement?
2. Experimental Model
Present and discuss the linear fit of your load versus strain measurements.
Report the numerical values you determined for the experimental model. Report the parameters of your curve fit for ‘m’ and ‘b’ along with the R2 value (squared correlation coefficient) for the experimental results.
You should also report the standard error of the fit (see Chapter 6 of your textbook).
What do the R2 and standard error values suggest about the efficiency of your experimental model?
Produce a graph that shows the data, and the linear model. Include this plot as a properly formatted figure in your report.
3. Model-Experiment Comparison
Illustrate the comparison between the mathematical model and the experimental measurements. You have both an analytical model for the relationship between tip force and strain (the mathematical model from your pre-lab, using the actual measurements for the beam from lab) and an empirical model based on the linear fit of your laboratory data.
Your comparison should include one figure that plots strain (at the strain gauge) versus tip load. The plot should include your time- averaged observations for the 10 tip load values, the empirical linear model (a least-squares best linear fit of the data) and a plot of the analytical prediction from your pre-lab.
4. Estimate of unknown force (AKA mystery box)
Based on your calibration curve you should be able to estimate the weight of the unknown load.
Estimate the weight of the unknown mystery load.
Quantify the uncertainty of your estimate of the mystery load. What is the accuracy and precision of your estimate (with units)? One way to quantify the accuracy of your estimate is to compare it to a known value. If you send an email to the instructors with your estimate of the mystery load, they will reply with the “true” mystery load mass as measured by a scale.
Your lab report should be a single document that discusses the topics above, and it should also include a short introduction and summary. The evaluation of your lab report will be based on your clear communication of the main results of the laboratory exercise. Your MATLAB scripts can be attached in the appendix of the lab report.
Note on the units of strain
Although strain is a unitless quantity, it is common practice to express the strain as the ratio of two length units, for example, as m/m or in/in. Because the strain is usually a very small number, it is often better to express strain as units of μm/m (micrometers per meter). In this sense, a strain of 0.001 would be expressed as 1000 μm/m. In general, the smallest value of strain encountered in most applications is 1 μm/m. Also note that some documents use “με” (i.e., mu epsilon) instead of μm/m.
1. See the directions from Lab 0 for setting up the strain gauge. Use the multimeter to measure the resistance of the gauge, it should be very close to 120 Ω.
2. Using your multimeter, measure and record the excitation voltage supplied by the 9 V battery. This is a good time to open a spreadsheet and record your measurements. Record the excitation voltage each time you make a measurement from the strain gauge.
3. Now install the beam on a table. Using your multimeter, zero the output of your Wheatsone bridge module for the no-load condition, i.e, adjust the potentiometer (with a screwdriver) in the Wheatstone bridge module so that the multimeter shows zero volts on the output of the Wheatstone bridge. Before each strain gauge measurement you will need to repeat the process to zero the output of the Wheatstone bridge. This is known as balancing the bridge.
4. You can apply a test load by hand, being careful not to cause plastic deformation of the beam. Using the multimeter, verify that as you apply a tip load down (towards the floor) you measure a positive voltage. If instead you measure a negative voltage, simply reverse the connection to the multimeter.
5. Next you will need to connect the output of the Wheatstone bridge to the data acquisition system. Verify that the MMC USB-1408FS data acquisition system is installed on your PC and that the TracerDAQ Strip Chart application is collecting data from the DAQ (USB-1408FS DAQ System Datasheet, User Manual, Set up Help and TracerDAQ Software Quick Start Guide, User Manual).
6. Configure the USB DAQ device by specifying the following parameters:
Input Type: Differential
Voltage Range: Choose the smallest voltage range that encompasses the entire anticipated input range. You should be able to predict this from your lab assignments.
Sample rate and duration: Since we are measuring the static response of the beam, we can use any sample rate. Set the rate to 100 Hz and the duration to 1 second.
7. Electrically connect the Wheatstone bridge to Channel 0 of the DAQ (CH0, Pin 1 and Pin 2). (You can use any channel, but make sure that you setup the DAQ for one channel of input and double check the pinout for the DAQ.)
8.Repeat the test load (by hand) to measure the voltage output of the bridge. Verify that the voltage you read with the DAQ is similar to what you measured with the multimeter. Also, verify that the measured voltage is positive when the tip of the beam is deflected down.
Now we have a setup that measures the voltage output from the Wheatstone bridge. From this voltage we can infer the strain measured by the strain gauge. Now we will apply a set of static loads to the end of the beam, and for each load we will measure the strain.
1. With the eye bolt and hanger assembly on the beam, zero the output of your Wheatstone bridge by adjusting the potentiometer (Help link).
2. The following steps describe a single measurement of strain for a given load. Repeat the follow steps 10 times, each time applying a known load using the supplied weights.
Hang the weight from the tip of the beam. (Be careful to stop any vibration before starting the static measurement of strain.)
Collect 1 second of data using the DAQ at 100 Hz and export the data as an appropriately labeled text file. Make sure you are saving the data in .txt or .csv format!
Measure the excitation voltage applied to the Wheatstone bridge; it will not be exactly 9.0 V! You can measure the excitation voltage using the multimeter. Make this measurement for each calibration data point and record the value for each run in a spreadsheet.
In the previous experiment you measured the strain for known weights. This will allow us to build an experimental characterization of the relationship between strain and load.
Next we'll repeat this experiment for an unknown “mystery weight”. Repeat the steps above for making a strain measurement, but instead of using a known weight use one of the supplied mystery weights. Again, record 1 second of data from the DAQ at 100 Hz. Also make note of the excitation voltage. In the analysis section you will use your pre-lab model and your experimental characterization to predict the value of the mystery weight. Make sure you take a note of which mystery weight you use (We have two in the lab - A and B), which will be crucial in comparing the result and calculating error.
You should have data files for each experimental run where each file contains 1 second of voltage data sampled at 100 Hz. The first analysis step is to use MATLAB calculate the average voltage for each run.
Write a MATLAB script (a .m file) that will accomplish the following:
Import the measurements from one run of the DAQ hardware
Calculate the time-average voltage and the standard deviation of the voltage
Make a plot of the voltage measurements and the average voltage as a function of time.
Report the time-averaged voltage to the workspace
Here is an outline of one way you might consider accomplishing this:
Create a new folder called “lab1_analysis”.
Put all your data files (.txt or .csv) in that same folder along with the “importStripChartData.m” function.
Create a new MATLAB script called “taverage.m” and save it to the same folder.
Within the script include the following:
Declare a variable called “fname” that contains the name of one of your data files.
fname = 'lab2_run1.txt' % (Note the single quotes around the name of the data file)
Call the importStripChartData() function to get the data from the data file.
[datavec,timevec,Ts] = importStripChartData(fname)
At this point we have a minimal working script. This is a good time to save the script and attempt to run it to make sure it works. Run the program. Now in the workspace make sure that you have what you expect for the outputs “datavec” and “timevec”. You can examine these variables from the workspace (AKA the command line) by one (or more) of the following:
size(datavec)
length(datavec)
plot(timevec,datavec,'.')
Create a variable containing the average (the mean) of the voltage measurements (see the mean() function.) Do not put a semicolon (;) at the end of this line. This will tell MATLAB to report the variable to the workspace.
fmean=mean(datavec)
Create a variable containing the standard deviation of the voltage measurements (see the std() function.) Do not put a semicolon (;) at the end of this line. This will tell MATLAB to report the variable to the workspace.
fstd=std(datavec)
Again, run you script and see if it works.
Create a new figure window
figure()
% Plot the measurements as a function of time.
% Use red dots to indicate the individual measurements, i.e., the line type is 'r.'
plot(timevec, datavec, 'r.')
% Include a statement to turn on the hold behavior so that you can add more data to the plot.
hold on;
% Plot a line (a black dashed line, 'k--') to indicate the value of the average voltage.
plot([x1,x2],[fmean,fmean],'k--') % (replace x1 and x2 with appropriate values)
% Add a legend, a title and axis labels (with engineering units)
title('your title')
xlabel('your x label [with unit]')
ylabel('your y label [with unit]')
legend('first curve [with unit]','second curve [with unit]')
Now, once you have all this working you should be able to run the script and it will generate the figure and report the mean and standard deviation to the workspace.
Now you will want to run this script for each of your data files. We are to use a brute force method of doing this. If we had 1,000 data files we might think about a way to automate it, but for now we’ll just do it by hand.
Comment out the first line of your script that declares the fname variable and add a new line just below that declares the fname variable as your next data file.
% fname = 'lab2_run1.txt'
fname = 'lab2_run2.txt'
The reason to do this, rather than just editing the first line, is that you can now switch which data file you are looking at by inserting/deleting appropriate comments. This way if you need to go back and re-examine one of the runs it is easy. Also, MATLAB has a convenient shortcut for adding comments and /removing comments (Ctrl+R or Ctrl+T), see the “Text” menu in the editor.
Now, as you move through your 10 runs you can collect all the data you need to create the curve fit of load versus strain. To facilitate this you should open another script. Let’s call it “curve_fit.m”. Declare two variables: “tipload” and “meanvoltage”. Each variable will be a vector of length 10. For example, if I had analyzed four runs my script might look like this:
% This is my curve_fit.m script (replace numbers with your measurements!)
tipload = [0.1, 0.2, 0.25, 0.42]; %[N]
meanvoltage = [0.0012, 0.0024, 0.0034, 0.0037]; %[V]
When you are done, you can plot the voltage versus load to check the results. Notice each data point is indicated with a red circle ('ro').
plot(tipload,meanvoltage,'ro')
Because of the pre-lab work, we would expect the relationship between measured strain (ε) and the applied force (F) to be a simple linear relation. For example, you may have derived an mathematical model similar to the following equation:
This mathematical model expresses a linear relationship between beam strain and applied force. However, there is considerable uncertainty in the actual material properties, beam dimensions and location of the strain gage, so we will use the measured data to generate a linear experimental model of the form,
In order to 'fit' the linear model to the data we need to determine numerical values for the constants m and b.
An important part of empirically identifying a mathematical model from experimental data is to report on the quality of the model, i.e., the “goodness of fit” of the chosen model. For linear polynomial models this is typically quantified by the correlation coefficient R, which is often reported as the coefficient of determination (often just called the R2 value).
From the previous exercise you should have a script called “curve_fit.m” that declares two variables. Each variable should be of length 10 — “tipload” and “meanvoltage”.
Before we start to fit the data, we’ll need to convert the measured voltage values to measured strain values. From the pre-lab you can determine the relationship between voltage from the Wheatstone bridge and strain; this is the sensitivity of our sensor. To use MATLAB to convert the voltage values to strain values you should use an element-wise multiplication of the meanvoltage, like this:
meanstrain = K*meanvoltage;
where ‘K’ is a scalar constant.
% This is my curve_fit.m script
tipload = [0.1, 0.2, 0.25, 0.42]; %[N]
meanvoltage = [0.0012, 0.0024, 0.0034, 0.0037]; %[V]
GF = 2; % Gauge Factor
exciteV = [9, 8.9, 8.8, 8.7]; % Excitation voltage for each run [V]
Strains = meanvoltage./exciteV*4/GF; % Estimated strain [m/m]
Now we can use the polyfit() function to fit a 1st order polynomial to the data. Please read the MATLAB documentation on using the polyfit() function. The results of the polyfit() function will provide you with experimentally derived values for your linear experimental model (m,b).
Once you have determined an empirical model (using polyfit()) you should be able to create one graph showing the following:
The data from the 10 runs with a known load (individual data points). Plot as red circles ('ro').
The linear fit of the data represented as a line. Plot as a red line ('r-').
The mathematical model from the prelab, represented as a black dashed line (k--').
The strain for the mystery load. Plot as blue squares ('bs')
The x-axis of this figure should be load and the y-axis should be strain with appropriate units. Include a legend!
Here is a full example of a MATLAB script for linear regression:
% Linear Regression Example
% The "data" below is the fictitous measurements we are going to fit with a line.
tipload = [1, 2, 4.5, 7.2]; % Tip force row vector [N]
meanvoltage = [0.001, 0.0022, 0.0035, 0.0049]; % Time-avg. [V]
GF = 2; % Gauge Factor
exciteV = [9, 8.9, 8.8, 8.7]; % Excitation voltage for each run [V]
Strains = meanvoltage./exciteV*4/GF; % Estimated strain [m/m]
% Plot the measurements
figure(1); clf();
plot(tipload,Strains,'o')
xlabel('Force [N]')
ylabel('Strain [m/m]')
% Fit a line (order 1) to the data
P = polyfit(tipload,Strains,1);
% Now evaluate the model at the known x points (this is our model prediction)
ForceVec = linspace(0,10,11)
StrainLinear = polyval(P,ForceVec)
% Add the model to our plot
% Plot the measurements
figure(1); clf();
plot(tipload,Strains,'o')
hold on
plot(ForceVec,StrainLinear,'r--')
xlabel('Force [N]')
ylabel('Strain [m/m]')
% Quantify the "goodness of fit" using the R-squared value
Rmatrix = corrcoef(tipload,Strains);
Rsquared = Rmatrix(2,1)^2;
% Add these evaluations of the model to the plot
title('Linear Fit Example');
msgR2 = ['Fit: R^2=' num2str(Rsquared)]
legend('Measurements',msgR2,'location','northwest');
% Plot experimental Model (from previous calculation)
figure(2);
clf();
plot(tipload,Strains,'o')
hold on
plot(ForceVec,StrainLinear,'r--')
xlabel('Force [N]')
ylabel('Strain [m/m]')
% Plot mathematical Model (from prelab)
strainModel = P(1)*1.2*ForceVec;
% IMPORTANT NOTE: This is NOT a proper mathematical model of the system.
% Replace strainModel equation with mathematical model from the prelab: epsilon=F(x-l)h/(2EI)
plot(ForceVec,strainModel,'g','linewidth',2);
legend('Measurements',msgR2,'Model','location','northwest');
Use these links to download the files for this lab: