Skip Navigation
USGS - science for a changing world

Woods Hole Coastal and Marine Science Center

Skip Navigation

Sediment Transport Instrumentation Facility - Publications


Benthic Acoustic Stress Sensor (BASS):
Electronics Check-Out Procedures

November 22, 1994

Marinna A. Martini, U.S. Geological Survey
Albert Williams III, Woods Hole Oceanographic Institution

U.S. Geological Survey Open File Report OF-93-722


Appendix D. MATLAB Script File for BASS Calibration

%function [cal_cms_in, bass_cms_out, fit_err, calc_factor] = 

%    basscal(bass_count, cal_ns_in, avgint, offset, file);


%       display the results from a bass calibration with 

%           least squares fit, compute the conversion factor for 

%			each calibration data point, plot the results.

%       bass_count = bass raw data in counts, a cumulative sum of

%			samples collected over the given average interval avgint

%       cal_ns_in = calibrator's ns delay input to BASS

%       avgint = number of samples per data point

%	    offset = ns delay offset applied to zero the output at start

%	    file = filename in which to save text output

%       cal_cms_in = calibrator's delay input in cm/s 

%		bass_cms_out = cm/s computed from the BASS output

%       fit_err = error from a linear fit to the BASS output

%       calc_factor = the count to cm/s conversion factor based on each data point


% Written by Marinna Martini for the

% U.S. Geological Survey, Woods Hole, MA

function [fit_err, calc_factor] = ...

    basscal(bass_count, cal_ns_in, avgint, offset, file);

if exist('avgint') ~= 1,

        avgint = 1;     % assume no averaging


% ---- account for the offset

if exist('offset') ~= 1, offset = 0; end

% ---- convert to real units

Factor = 0.03;          % 0.03 cm/s per count

bass_cms=(bass_count./avgint).*Factor;	% BASS normalized using generic factor

cal_cms_in=cal_ns_in.*0.75;		% 0.75 cm/s per ns


% ---- liner fit


c = polyfit(cal_ns_in, bass_cms,1);

fit_cms = polyval(c, cal_ns_in);


% *********************** upper plot **************************

ptr=axes('Position',[0.15 0.1 0.8 0.6]);

% ---- display fit and data points



if mean(bass_cms) > 0,

	set(ptr,'ylim',[0 120],'xlim',[0 160]);


	set(ptr,'ylim',[-120 0],'xlim',[-160 0]);


%title('BASS Calibration Linearity Check')

text('units','normalized','position',[0.01 0.85],'string','--- least squares fit')

text('units','normalized','position',[0.01 0.90],'string',' X  BASS output')

text('units','normalized','position',[0.01 0.95],'string','- - Calibrator Input')

xlabel('Nanosecond Delay')



txt=sprintf('mean(calibrator-BASS) = %7.4f',mean(cal_cms_in-bass_cms));

text('units','normalized','position',[0.5 0.05],'string',txt)

txt=sprintf('fit error: std = %7.4f',std(fit_err));

text('units','normalized','position',[0.6 0.1],'string',txt)

% *********************** lower plot *************************

ptr=axes('Position',[0.15 0.725 0.8 0.15]);

% ---- plot different in cm/s


if mean(bass_cms) > 0,

	set(ptr,'ylim',[0.028 0.032 ],'xlim',[0 160]);


	set(ptr,'ylim',[0.028 0.032],'xlim',[-160 0]);


ylabel('cm/s per count')


text('units','normalized','position',[0.01 1.1],'string',...

	'Conversion factor computed from calibration data');


text('units','normalized','position',[0.45 1.5],...


	'string',['BASS: Linearity Check ',date]);


% ------- Generate Text Report


if exist('file') == 1,	% user wants output

	if exist(file) >= 2,	% file already exists

		disp([file ' already exists.  Saving to basscal.out'])


        delete basscal.out,


    eval(['diary ' file])


fprintf ('\n')

fprintf('   BASS Calibration %s\n', date)


fprintf('Delay Input\tOut: BASS, Fit\tError  Factor\n')

fprintf('ns\tcm/s\tcm/s\tcm/s\tcm/s\tcm/s per count\n')

for j=1:l,

    fprintf('%04.1f\t%04.1f\t%6.3f\t%6.3f\t%5.3f\t%6.4f\n', cal_ns_in(j),...

	cal_cms_in(j), bass_cms(j), fit_cms(j), fit_err(j), calc_factor(j));


fprintf('\nOffset applied to zero BASS output: %4.2f ns\n',offset);

fprintf('Number of samples averaged per calibration point: %3.0f\n',avgint);

fprintf('Mean(calibrator-BASS) = %7.4f cms\n',mean(cal_cms_in-bass_cms));

fprintf('Fit error: std = %7.4f cms\n',std(fit_err));

if exist('file') == 1,

    diary off


Back to contents - Previous section


Skip Navigation

Accessibility FOIA Privacy Policies and Notices

Take Pride in America logo USAGov logo U.S. Department of the Interior | U.S. Geological Survey

Page Contact Information: WHSC Webmaster
This page last modified on Monday, 24-Nov-2014 13:06:01 EST