acquire data from an accelerometer -pg电子麻将胡了
this example shows how to acquire and display data from an accelerometer attached to a vehicle driven under uneven road conditions.
discover devices that support accelerometers
to discover a device that supports accelerometers, access the device in the table returned by the daqlist command. this example uses national instruments® compactdaq chassis ni cdaq-9178 and module ni 9234 with id cdaq1mod3.
d = daqlist("ni")
d =
12×4 table
deviceid description model deviceinfo
___________ __________________________________ _____________ ____________________
"cdaq1mod1" "national instruments ni 9205" "ni 9205" [1×1 daq.deviceinfo]
"cdaq1mod2" "national instruments ni 9263" "ni 9263" [1×1 daq.deviceinfo]
"cdaq1mod3" "national instruments ni 9234" "ni 9234" [1×1 daq.deviceinfo]
"cdaq1mod4" "national instruments ni 9201" "ni 9201" [1×1 daq.deviceinfo]
"cdaq1mod5" "national instruments ni 9402" "ni 9402" [1×1 daq.deviceinfo]
"cdaq1mod6" "national instruments ni 9213" "ni 9213" [1×1 daq.deviceinfo]
"cdaq1mod7" "national instruments ni 9219" "ni 9219" [1×1 daq.deviceinfo]
"cdaq1mod8" "national instruments ni 9265" "ni 9265" [1×1 daq.deviceinfo]
"dev1" "national instruments pcie-6363" "pcie-6363" [1×1 daq.deviceinfo]
"dev2" "national instruments ni elvis ii" "ni elvis ii" [1×1 daq.deviceinfo]
"dev3" "national instruments pcie-6363" "pcie-6363" [1×1 daq.deviceinfo]
"dev4" "national instruments pcie-6363" "pcie-6363" [1×1 daq.deviceinfo]
deviceinfo = d{3, "deviceinfo"}
deviceinfo =
ni: national instruments ni 9234 (device id: 'cdaq1mod3')
analog input supports:
-5.0 to 5.0 volts range
rates from 1000.0 to 51200.0 scans/sec
4 channels ('ai0','ai1','ai2','ai3')
'voltage','accelerometer','microphone','iepe' measurement types
this module is in slot 3 of the 'cdaq-9178' chassis with the name 'cdaq1'.
add an accelerometer channel
create a dataacquisition, and add an analog input channel with accelerometer measurement type.
dq = daq("ni"); ch = addinput(dq, "cdaq1mod3", "ai0", "accelerometer");
set the scan rate
change the acquisition scan rate to 4000 scans per second.
dq.rate = 4000;
set the sensitivity
you must set the sensitivity value to the value specified in the accelerometer's data sheet. this example uses a ceramic shear accelerometer model 352c22 from pcb piezotronics with 9.22 mv per gravity.
ch.sensitivity = 0.00922; ch
ch =
index type device channel measurement type range name
_____ ____ ___________ _______ ______________________ ____________________ _______________
1 "ai" "cdaq1mod3" "ai0" "accelerometer (diff)" "-5.0 to 5.0 volts" "cdaq1mod3_ai0"
acquire and plot data
use the read command to acquire data for 30 seconds.
data = read(dq, seconds(30));
plot(data.time, data.cdaq1mod3_ai0);
ylabel("acceleration (gravities)");
