% % This program will output calibration coefficients for % the three wave probes used in the 13.021 WAVES lab. % % This is designed to work in MATLAB for windows -- It can be % adjusted to work in UNIX as well. % % 28 Nov 2000 -- Alex Techet % MIT Towing Tank % % QUESTIONS? ahtechet@mit.edu % %open window to get calibration data file: [filen, pathn] = uigetfile('*.i32','OPEN Calibration Data File'); filestub = [pathn '' filen]; %Load i32 format data and create array with channel 1,2,3 in columns: cald = parsedl2(filestub,3); caldata = cald'; figure(1);clf; plot(caldata); xlabel('time (s)'); ylabel('Probe reading in Volts'); legend('CH 1','CH 2','CH 3'); % INPUT 3 CALIBRATION HEIGHTS: disp(sprintf('\n')); h1 = input('ENTER THE HEIGHT OF THE FIRST CALIBRATION IN CM --> [2.54] '); if length(h1) == 0 h1 = 2.54; end; h2 = input('ENTER THE HEIGHT OF THE SECOND CALIBRATION IN CM --> [5.08] '); if length(h2) == 0 h2 = 5.06; end; h3 = input('ENTER THE HEIGHT OF THE THIRD CALIBRATION IN CM --> [8.62] '); if length(h3) == 0 h3 = 8.62; end; disp(sprintf('\n ~~~~~~~~~~~~~~CALIBRATION HEIGHTS~~~~~~~~~~~~~')); disp(sprintf(' First calibration height was: %4.2f cm',h1)); disp(sprintf(' Second calibration height was: %4.2f cm',h2)); disp(sprintf(' Third calibration height was: %4.2f cm',h3)); %Calibrate Channels: % FIRST FIND ZERO REGIONS! % % figure(2);clf; plot(caldata(:,1),'b'); title('Pick TWO ZERO regions for CHANNEL 1'); ctmp1 = ginput(2); zero_off1 = mean(caldata(round(ctmp1(:,1)),1)); %this is the zero offset of channel 1! plot(caldata(:,1)-zero_off1,'b'); title('press space to continue'); pause; plot(caldata(:,2),'g'); title('Pick TWO ZERO regions for CHANNEL 2'); ctmp2 = ginput(2); zero_off2 = mean(caldata(round(ctmp2(:,1)),2)); %this is the zero offset of channel 2! plot(caldata(:,2)-zero_off2,'g'); title('press space to continue'); pause; plot(caldata(:,3),'r'); title('Pick TWO ZERO regions for CHANNEL 3'); ctmp3 = ginput(2); zero_off3 = mean(caldata(round(ctmp3(:,1)),3)); %this is the zero offset of channel 3! plot(caldata(:,3)-zero_off3,'r'); title('press space to continue'); pause; z_data = [caldata(:,1)-zero_off1 caldata(:,2)-zero_off2 caldata(:,3)-zero_off3]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % NOW FIND VOLTS/CM for each channel %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp(' '); disp('CALIBRATING CHANNEL 1...'); plot(z_data(:,1),'b'); title('PICK A POINT IN EACH CALIBRATION REGION 1,2,3 (DOWNWARD DISPLACEMENT)'); [xt,yt] = ginput(3); xt = round(xt); yt = z_data(xt,1)'; figure(3);clf; hmat = [0 h1 h2 h3]; vmat = [0 yt]; plot(vmat, hmat,'b*'); ylabel('height in CM'); xlabel('voltage'); %Plot linear fit and get slope hold on; %p1 is the slope of a first order linear fit to the calibration... p1 = polyfit(vmat,hmat,1); %PLOT a line with the slope p1 pv1 = polyval(p1,vmat); plot(vmat,pv1,'b'); ccal1 = p1(1); %calibration coef for channel 1: disp('CALIBRATING CHANNEL 2...'); figure(2); plot(z_data(:,2),'g'); title('PICK A POINT IN EACH CALIBRATION REGION 1,2,3 (DOWNWARD DISPLACEMENT)'); [xt,yt] = ginput(3); xt = round(xt); yt = z_data(xt,2)'; figure(3); hmat2 = [0 h1 h2 h3]; vmat2 = [0 yt]; plot(vmat2, hmat2,'g*'); ylabel('height in CM'); xlabel('voltage'); %Plot linear fit and get slope hold on; %p2 is the slope of a first order linear fit to the calibration... p2 = polyfit(vmat2,hmat2,1); %PLOT a line with the slope p2 pv2 = polyval(p2,vmat2); plot(vmat2,pv2,'g'); ccal2 = p2(1); %calibration coef for channel 2: disp('CALIBRATING CHANNEL 3...'); figure(2); plot(z_data(:,3),'r'); title('PICK A POINT IN EACH CALIBRATION REGION 1,2,3 (DOWNWARD DISPLACEMENT)'); [xt,yt] = ginput(3); xt = round(xt); yt = z_data(xt,3)'; figure(3); hmat3 = [0 h1 h2 h3]; vmat3 = [0 yt]; plot(vmat3, hmat3,'r*'); ylabel('height in CM'); xlabel('voltage'); %Plot linear fit and get slope hold on; %p3 is the slope of a first order linear fit to the calibration... p3 = polyfit(vmat3,hmat3,1); %PLOT a line with the slope p1 pv3 = polyval(p3,vmat3); plot(vmat3,pv3,'r'); ccal3 = p3(1); %calibration coef for channel 1: zero_off = [zero_off1 zero_off2 zero_off3]; ccoefs = [ccal1 ccal2 ccal3]; disp(sprintf('\n ~~~~~~~~~~~~~~CALIBRATION COEFFICIENTS~~~~~~~~~~~~~')); disp(sprintf('CHANNEL 1: ZERO = %8.2f Volts; CalCoeff = %8.2f cm/Volts',zero_off1,ccal1)); disp(sprintf('CHANNEL 2: ZERO = %8.2f Volts; CalCoeff = %8.2f cm/Volts',zero_off2,ccal2)); disp(sprintf('CHANNEL 3: ZERO = %8.2f Volts; CalCoeff = %8.2f cm/Volts',zero_off3,ccal3)); disp(sprintf('\n SAVING DATA TO FILE cal.mat')); save cal.mat zero_off ccoefs disp(sprintf('ALL DONE!! \n'));