This notebook demonstrates how to use Mathematica to control a bTop-2 device for analog input and output.

We begin, as always, by loading the BTopTools package.

<<BTopTools`

BTopAnalog can be used to get a single sample from a set of analog input channels.  Here we ask the first connected bTop-2 for the voltages on its analog input channels 0, 1, and 3:

BTopAnalog[BTopDevice[1], {0, 1, 3}]

RowBox[{{, RowBox[{{, RowBox[{2.45543, ,, 0, ,, 0}], }}], }}]

We can set voltages on the output channels using a similar command.  Here we set the voltage on channel 1 of the first connected bTop to 1.5V:

RowBox[{RowBox[{BTopAnalog[BTopDevice[1], {1}], =, RowBox[{{, 1.5, }}]}], ;}]

We can loop output channel one back to an input channel to see if that last command worked.  Here I've looped output channel 1 back to input channel 3:

BTopAnalog[BTopDevice[1], {3}]

RowBox[{{, RowBox[{{, 1.51526, }}], }}]

We can take analog samples at a controlled rate using the BTopAnalog function as well, by using two extra arguments.  The next command takes 4000 samples from channel 0 of the first connected bTop-2, at a rate of 1000Hz:

RowBox[{RowBox[{data, =, RowBox[{BTopAnalog, [, RowBox[{BTopDevice[1], ,, {0}, ,, 4000, ,, 1000.}], ]}]}], ;}]

We extract the analog data from the first channel of the first connected bTop- 2, and play the tone:

soundData = Table[data[[1]][[j]][[1]], {j, 1, Length[data[[1]]]}] ; RowBox[{RowBox[{ListPlay, [, RowBox[{soundData, ,, RowBox[{SampleRate, , 1000.}]}], ]}], ;}]

[Graphics:HTMLFiles/btop_analog_9.gif]

We can send the analog signal straight into Mathematica's Fourier function.  In this case I used a signal generator to get a pure sine wave

f = Fourier[soundData] ; ListPlot[Abs[Take[f, Floor[Length[f]/2] + 1]], {PlotJoinedTrue, PlotRange {0, 1}}] ;

[Graphics:HTMLFiles/btop_analog_11.gif]


Created by Mathematica  (January 24, 2007)