Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

rheodyneobjpulse(time)
function [waveform, timeCoords] = rheodyneobjpulse(time)
% RHEODYNEOBJPULSE generates the sound which changes the Rheodyne valve 
% from position 1 to 2 then 1 again - designed to be able to be repeated
% without any issues.  A transition from 1 to -1 sets the valve in position
% A, and from -1 to 1 in position B.

% checks the number of arguments
error(nargchk(1, 1, nargin))

% error handling
if ~isnumber(time) || ~isscalar(time) || ~isreal(time) || time <= 0 || isnan(time) || isinf(time)
    % errors
    error('Time must be a real number (in seconds) greater than 0')
end

% sample frequency in Hz (8192 Hz is the default MATLAB value for
% playing sounds using SOUND)
sampleFrequency = 8192;

% defines the spacing
sampleSpacing = 1 / sampleFrequency;

% forms the time co-ordinates (chopping off the last sample on purpose - if
% we want to repeat this sample, then 0 and the time (e.g. 5 s) would be
% the same point so they'd overlap - so actually the time goes from 0 to
% 4.999878...
timeCoords = 0:sampleSpacing:time - sampleSpacing;

% forms a single rectangular wave with period time, returning
% it to the output argument
waveform = rectWave(timeCoords, time);

% then transforms it some more to save space
waveform = int8(waveform);
waveform(waveform < 0) = -128;
waveform(waveform >= 0) = 127;


function rect = rectWave(timeCoords, period)
% RECTWAVE unashamedly modified from rectpuls from the MATLAB Signal
% Processing Toolbox for those who don't have it installed.

% Returns unity in interval [-period / 2, +period / 2] (right side of
% interval is open)
rect = abs(timeCoords) < (period / 2);
rect(timeCoords == -(period / 2)) = 1;

% then changes the intensity (at the moment its 0-1 - we want it to be
% -1-1)
rect = rect * 2 - 1;

Contact us