diff --git a/applications/apertif/designs/apertif_unb1_fn_bf_emu/tb/python/tc_apertif_unb1_fn_bf_emu.py b/applications/apertif/designs/apertif_unb1_fn_bf_emu/tb/python/tc_apertif_unb1_fn_bf_emu.py index 6de49685a21f7c6673c2a07fd0542fef38e7e720..9b7f78edbf8710b6c7f45ac504f9056ef20869dc 100644 --- a/applications/apertif/designs/apertif_unb1_fn_bf_emu/tb/python/tc_apertif_unb1_fn_bf_emu.py +++ b/applications/apertif/designs/apertif_unb1_fn_bf_emu/tb/python/tc_apertif_unb1_fn_bf_emu.py @@ -30,9 +30,12 @@ # looped through by the block generator; # . Each BG stream contains 2*64 = 128 timesamples; # . This TC overwrites the default block gen RAM contents. +# . All 4*2=8 BG output signals will be the same. # Usage: -# . Change CHANNELS as desired; -# . python tc_apertif_unb1_fn_bf_emu.py --unb 3 --fn 0:2 +# . python tc_apertif_unb1_fn_bf_emu.py --unb 3 --fn 0 -r [channels] -n [phase shift] +# . Pass -s noplot to disable plotting. +# Example: +# . python tc_apertif_unb1_fn_bf_emu.py --unb 3 --fn 0 -r 3,5,7,34,60 -n 0 import test_case import node_io @@ -60,17 +63,22 @@ io = node_io.NodeIO(tc.nodeImages, tc.base_ip) bg = pi_diag_block_gen.PiDiagBlockGen(tc, io, NOF_STREAMS, NOF_RAM_WORDS_PER_STREAM) ############################################################################### -# Define which channels are present in the BG output signal -# . A sub-signal is created for each channel number (a.k.a. bin number) defined -# in CHANNELS. -# . All sub-signals are added yielding our composite signal +# Assign the user passed arguments -r and -n +# . CHANNELS (-r): +# . Define which channels are present in the BG output signal +# . A sub-signal is created for each channel number (a.k.a. bin number) defined +# in CHANNELS. +# . All sub-signals are added yielding our composite signal +# . PHASE_SHIFT_DEG (-n): +# . Pass a phase shift in degrees that is applied to each channel signal +############################################################################### +CHANNELS = tc.gpNumbers # -r argument +PHASE_SHIFT_DEG = tc.number # -n argument +NOPLOT=tc.gpString=='noplot' # True if -s noplot is passed + +############################################################################### +# Create the channel sub-signals and the resulting composite signal ############################################################################### -# Define your list of channel numbers 0..63) to put in the signal here -#CHANNELS = [1] -#CHANNELS = [60] -#CHANNELS = [1,60] -CHANNELS = [10] -#CHANNELS = [1,5,12,17,21,25,28,34,41,47,54,55,60] # Sample spacing T = 1.0 / NOF_WORDS_PER_SIGNAL @@ -80,10 +88,12 @@ x = np.linspace(0.0, NOF_WORDS_PER_SIGNAL*T, NOF_WORDS_PER_SIGNAL) channel_signals = [] NOF_CHANNELS = len(CHANNELS) for bin_nr in CHANNELS: + phase_shift_rad = phase_shift_rad = math.radians(PHASE_SHIFT_DEG) + # Make sure the summed amplitude of all channels does not exceed AMPL_MAX ampl=AMPL_MAX/NOF_CHANNELS # Create the signal in this channel and append to list - channel_signal = ampl * np.exp( bin_nr*1.j*(2.0*np.pi*x) ) + channel_signal = ampl * np.exp( bin_nr*1.j*(2.0*np.pi*x+(phase_shift_rad/bin_nr)) ) channel_signals.append( channel_signal ) # Adding all channel sub-signals yields our composite signal @@ -93,29 +103,30 @@ composite_signal=np.sum(channel_signals, axis=0) # Plot our composite signal + FFT # . This step is optional and not required to overwrite the RAM contents. ############################################################################### -# Convert the float values to 8-bit complex -s_bits = [] -for fword in composite_signal: - re_signed = to_signed(fword.real, COMPLEX_WIDTH) - im_signed = to_signed(fword.imag, COMPLEX_WIDTH) - s_bits.append( complex(re_signed, im_signed) ) - -# Define our axes and plot the signal -s = np.array(s_bits) -t = range(NOF_WORDS_PER_SIGNAL) -plt.plot(t, s.real, 'b-', t, s.imag, 'r--') -plt.legend(('real', 'imaginary')) -plt.show() - -# Calculate and plot the FFT -yf = fft(s) -xf = fftfreq(NOF_WORDS_PER_SIGNAL, T) -xf = range(NOF_WORDS_PER_SIGNAL) -xf = fftshift(xf) -yplot = fftshift(yf) -plt.bar(xf, 1.0/NOF_WORDS_PER_SIGNAL * np.abs(yplot)) -plt.grid() -plt.show() +if NOPLOT==False: + # Convert the float values to 8-bit complex + s_bits = [] + for fword in composite_signal: + re_signed = to_signed(fword.real, COMPLEX_WIDTH) + im_signed = to_signed(fword.imag, COMPLEX_WIDTH) + s_bits.append( complex(re_signed, im_signed) ) + + # Define our axes and plot the signal + s = np.array(s_bits) + t = range(NOF_WORDS_PER_SIGNAL) + plt.plot(t, s.real, 'b-', t, s.imag, 'r--') + plt.legend(('real', 'imaginary')) + plt.show() + + # Calculate and plot the FFT + yf = fft(s) + xf = fftfreq(NOF_WORDS_PER_SIGNAL, T) + xf = range(NOF_WORDS_PER_SIGNAL) + xf = fftshift(xf) + yplot = fftshift(yf) + plt.bar(xf, 1.0/NOF_WORDS_PER_SIGNAL * np.abs(yplot)) + plt.grid() + plt.show() ############################################################################### # Prepare the data to be written to RAM