Pseudo-random number generator in the run time of AWGs

This post discusses ways to generate noise signals within a well-defined frequency range, amplitude, defined distribution (white, Gaussian, etc.), and minimal correlation using Arbitrary Waveform Generators (AWG). Sample-by-sample programming of the waveform leads to very well-defined properties, but the signal length is limited by waveform memory and programming can be time-consuming. Playing tricks with predefined waveforms can lead to longer patterns at the cost of higher correlations. Zurich Instruments AWGs overcome both shortcomings using random numbers generated during run time. Let’s look at the following example: added phase noise on a waveform.

Generating a finite waveform containing random numbers of different distribution is simple when using a compiled programming language. The challenging part is to generate random numbers or pseudo-random numbers (PRNs) in the run time because of the lag of the multiplication operator. Nevertheless, PRNs can be generated using AND, bitwise shift, NOT, and OR operations. The basis is the XORshift-Algorithm [1], which can be considered as a linear-feedback shift register. This is a proven algorithm known for its fast execution and the good randomness of the obtained results; it even passes most of the DieHard tests [2]. The XORshift-Algorithm uses a bitwise shift and bitwise XOR (which can be represented with AND, OR and NOT) as the only elements.
The periodicity of the code depends on the implemented feedback. A list of parameters allowing for a maximum cycle length is provided in [Marsaglia 2003], making it possible to have a correlation length that is identical to the data type length.
Due to the lack of multiplication, PRNs of shorter length are derived taking the modulo with a finite number. In the run time this is accomplished performing XOR with (2^n)-1 with 2^n as the desired length.

To mimic the phase noise of a ramp we require PRNs of a value up to 256. Please see the full code snippet in Figure 1 below that starts with the definition of the waveforms used and the different variables. The PRN generator still runs on a length of 32bit for a repetition cycle of >>256.

Figure 1: LabOne SeqC code that defines the waveforms, implements the PRNG and plays the actual waveform.

It starts with a fixed seed value or can get one from the DIO port. Its parameters are adjusted so as to get a good mixing in the least significant bits for a length of 256. The PRN is then derived with XOR(255) which is modulo(256). The random value defines when the waveform containing the ramp is played in an indexed way within the while loop. Subsequently, the next PRN value is calculated. The resulting phase noise on the waveform is shown in Figure 2,  displaying the oscilloscope trace in persistence mode.

Figure 2: Oscilloscope trace with persistence exhibiting the phase noise on the Ramp waveform and the subsequent constant waveform.

For this application, the noise was uniformly distributed. Other applications might require Gaussian-distributed random numbers. Those can be generated thanks to a random waveform with a finite number of normally distributed values. Using the same procedure described above results in the indexed playback of a short subset of the waveform with a random starting point. Playing such short subsets of a normally distributed random waveform with a random starting point leads again to a noise structure with a Gaussian distribution of the values.

The analysis of such a noise trace is illustrated in Figure 3, showing the temporal trace (upper half) with the Histogram and the Fourier transform in the frequency domain (lower half). All depict the expected values. The Histogram exhibits a Gaussian distribution; the temporal trace is random and no patterns are discernible. In the frequency domain, a white noise spectrum is characterised by a roll-off at 900 MHz caused by the anti-aliasing filter at the AWG Output.

Figure 3: Oscilloscope measurement of Gaussian-distributed noise from the PRNG. The upper half depicts the temporal trace with a histogram.
The lower half shows the flat noise spectrum up to the anti-aliasing filter bandwidth of 900 MHz.

Program execution during run time is very powerful and adds a lot of flexibility. Using it for the generation of noise is great to demonstrate its capabilities, but it only scratches the surface of what’s possible – sequence and waveform adaptation, as well as decision making within the run time. So what’s your next project that employs direct manipulation in the run time?

References

[1] Marsaglia, George, 2003, Random number generators,
Journal of Modern Applied Statistical Methods, 2 No. 2.

[2] Marsaglia, George and Tsang, Wai Wan, 2002, Some difficult-to-pass tests of randomness,
Journal Statistical Software, 7, Issue 3.

Links

Here you find the example seqC code for:

1 comment to Pseudo-random number generator in the run time of AWGs