Data Acquisition Toolbox | ![]() ![]() |
Example: Performing a Linear Conversion
This example illustrates how to configure the engineering units properties for an analog input object connected to a National Instruments PCI-6024E board.
An accelerometer is connected to a device which is undergoing a vibration test. Your job is to measure the acceleration and the frequency components of the device while it is vibrating. The accelerometer has a range of ±50 g's, a voltage sensitivity of 99.7 mV/g, and a resolution of 0.00016 g.
The accelerometer signal is input to a Tektronix TDS 210 digital oscilloscope, and to channel 0 of the data acquisition board. By observing the signal on the scope, the maximum expected range of data from the sensor is ±200 mV, which corresponds to approximately ±2 g's. Given this constraint, you should configure the board's input range to the ±500 mV, which is the closest input range that encompasses the expected data range.
You can run this example by typing daqdoc5_8
at the MATLAB command line.
1. Create a device object - Create the analog input object AI
for a National Instruments board. The installed adaptors and hardware IDs are found with daqhwinfo
.
AI = analoginput('nidaq',1);
2. Add channels - Add one hardware channel to AI
.
chan = addchannel(AI,0);
3. Configure property values - Configure the sampling rate to 200 kHz and define a two second acquisition.
duration = 2; ActualRate = setverify(AI,'SampleRate',200000); set(AI,'SamplesPerTrigger',duration*ActualRate)
Configure the engineering units properties. This example assumes you are using a National Instruments PCI-6024E board or an equivalent hardware device. SensorRange
is set to the maximum accelerometer range in volts, and UnitsRange
is set to the corresponding range in g's.
set(chan,'SensorRange',[-5 5]) set(chan,'InputRange',[-0.5 0.5]) set(chan,'UnitsRange',[-50 50]) set(chan,'Units','g''s (1g = 9.80 m/s/s)')
4. Acquire data - Start the acquisition and wait until all the data is acquired.
start(AI) while strcmp(AI.Running,'On') end
Extract and plot all the acquired data.
data = getdata(AI); subplot(2,1,1),plot(data)
Calculate and display the frequency information.
Fs = ActualRate; blocksize = duration*ActualRate; [f,mag]= daqdocfft(data,Fs,blocksize); subplot(2,1,2),plot(f,mag)
5. Clean up - When you no longer need AI
, you should remove it from memory and from the MATLAB workspace.
delete(AI) clear AI
![]() | Linearly Scaling the Data: Engineering Units | Analog Output | ![]() |