jupyter-notebook

Using variable after declaring it in Jupyter Notebook RFsoc4x2


As you can see below, the Jupyter notebook (python based) is using
ol = mtsOverlay('mts.bit')
It is being defined in operation 5 while in operation 3 its being used.
How is this possible?
We are declaring a variable after we use it stage 3

X_axis = (1/DAC_SR) * np.arange(0,ol.dac_player.shape[0])

Thanks.

https://github.com/Xilinx/RFSoC-MTS/blob/main/boards/RFSoC4x2/notebooks/rfsocMTS.ipynb

enter image description here


Solution

  • ol.dac_player is initialized as part of the mtsOverlay object when you call ol = mtsOverlay('mts.bit').

    The full definition of mtsOverlay is here, in the same repo.

    The dac_player is initialized as a NumPy array. NumPy arrays are initialized with a shape (corresponding to length here as the array is one-dimensional). Thus is why you can access dac_player.shape in Cell 3.

    In Cell 5 ol.dac_player[:] = np.int16(DAC_sinewave) performs an in-place copy of the sine wave into the dac_player. The [:] syntax is used to replace the values of the array without creating a new one. See this StackOverflow post for more information on that syntax.