Matlab Scripts

The following matlab scripts are provided with MBF.

Fast memory readout

d = mbf_read_mem(mbf, turns ...
[, 'offset', offset] [, 'channel', channel], ...
[, 'lock', timeout] [, 'bunch', bunch | [, 'tune', tune] [, 'decimate', decimate]])

This function takes two mandatory arguments and six optional arguments and returns an array containing the requested memory. If the 'channel' argument is omitted the array has two columns (second dimension is 2), one for each captured channel, otherwise it is a single column.

ArgumentDescription
mbfThis is the device name of the machine from which to read. There needs to be a direct socket connection available to this machine.
turnsThis determines the number of turns of data to read.
'offset'This determines an offset in turns from the trigger point from which to start returning data. This can be positive or negative, though the valid range will depend on the runout setting in the memory configuration. The default value is 0 offset.
'channel'This can be specified as 0 or 1 to request readout of only the selected channel. As the readout rate is limited by the gigabit ethernet interface to the server this can be useful to increase readout speed.
'bunch'This can be set to select readout of a specific bunch instead of a complete turns. This is useful for retrieving an overview of the complete captured buffer. This option cannot be combined with 'decimate' or 'tune'.
'decimate'

If this is set then data will be reduced by bunch-by-bunch binned averaging before being returned. This is best combined with 'tune' to reduce the data transfer around the tune frequency of interest. This option cannot be combined with 'bunch'.

Large values of decimation are useful for increasing the data readout speed, but smaller values will slow retrieval down due to more readout processing required.

'tune'

If this option is set then the stored data will be frequency shifted by the given tune (in units of rotations per machine revolution). This is best combined with 'decimate' to reduce the amount of data processing required on the client side. This option cannot be combined with 'bunch'.

Note that due to the rather blunt instrument provided by 'decimate' it is necessary to combine these two settings rather carefully to avoid aliasing problems.

If this option is set then data is returned as frequency shifted complex numbers.

'lock'If set this will lock the readout channel to ensure that memory capture is not armed and is not retriggered during readout. The value is a timeout in seconds, if the memory cannot be locked within this time the readout will fail.

Detector readout

[d, s, t] = mbf_read_det(mbf [, 'axis', axis] [, 'lock', timeout])

One argument is mandatory, two are optional.

ArgumentDescription
mbfThe device name from which to read, same as above.
'axis'This determines which axis will be read and can be 0 or 1, the default is 0. For LMBF there is only one active detector axis, so this argument is not useful in this case.
'lock'This is used to lock the detector readout channel so that the sequencer is neither armed nor active during readout. As above, the timeout is in seconds.

Up to three results can be returned:

ResultDescription
dDetector data. The number of rows (first dimension) is determined by the number of samples captured into detector memory by the sequencer, all captured data is always returned. The number of columns (second dimension) is determined by the number of active detectors, with one column per active detector. Data is as complex numbers with delay phase compensation already applied.
sThis is the frequency scale in units of cycles per turn, and is a column vector of the same height as d.
tThis is a timebase scale in units of turns and is the same dimensions as s.

Tune PLL capture

result = mbf_read_tune_pll(mbf, [, axis], count, [, 'debug'] [, 'no_bar' | 'no_progress'] [, 'fresh'])

The axis  argument is mandatory when mbf  is in TMBF mode, must not be given when in LMBF mode.

This function captures live data from the Tune PLL system, which must be running.

ArgumentDescription
mbfThis names the MBF server from which data will be captured, not including the axis part of the name.
axisIn longitudinal mode this argument must be omitted, otherwise should be the name of the axis to be captured (typically 'X'  or 'Y'), or can name both axes (eg 'XY') to select simultaneous capture of data from both axes.
countThis identifies how many samples of data are to be captured.  In practice, data will be returned in multiples of the Tune PLL buffer length
'debug'By default the Tune PLL offset data (PV :PLL:NCO:OFFSETWF) is captured.  If this optional argument then debug IQ data is captured and returned instead.

'no_bar'

'no_progress'

By default a graphical progress bar is shown during capture.  If 'no_bar'  is specified (or if Matlab is in non graphical mode) progress is shown on the command line, or 'no_progress'  can be specified to suppress progress reporting altogether.
'fresh'This optional argument forces the first buffer of data to be discarded to ensure that the captured data is not stale.