Skip to content
Snippets Groups Projects
Commit 5c7a2182 authored by Daniel van der Schuur's avatar Daniel van der Schuur
Browse files

-Added command line args.

parent 9e7a56de
No related branches found
No related tags found
No related merge requests found
...@@ -30,9 +30,12 @@ ...@@ -30,9 +30,12 @@
# looped through by the block generator; # looped through by the block generator;
# . Each BG stream contains 2*64 = 128 timesamples; # . Each BG stream contains 2*64 = 128 timesamples;
# . This TC overwrites the default block gen RAM contents. # . This TC overwrites the default block gen RAM contents.
# . All 4*2=8 BG output signals will be the same.
# Usage: # Usage:
# . Change CHANNELS as desired; # . python tc_apertif_unb1_fn_bf_emu.py --unb 3 --fn 0 -r [channels] -n [phase shift]
# . python tc_apertif_unb1_fn_bf_emu.py --unb 3 --fn 0:2 # . 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 test_case
import node_io import node_io
...@@ -60,17 +63,22 @@ io = node_io.NodeIO(tc.nodeImages, tc.base_ip) ...@@ -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) 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 # Assign the user passed arguments -r and -n
# . A sub-signal is created for each channel number (a.k.a. bin number) defined # . CHANNELS (-r):
# in CHANNELS. # . Define which channels are present in the BG output signal
# . All sub-signals are added yielding our composite 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 # Sample spacing
T = 1.0 / NOF_WORDS_PER_SIGNAL 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) ...@@ -80,10 +88,12 @@ x = np.linspace(0.0, NOF_WORDS_PER_SIGNAL*T, NOF_WORDS_PER_SIGNAL)
channel_signals = [] channel_signals = []
NOF_CHANNELS = len(CHANNELS) NOF_CHANNELS = len(CHANNELS)
for bin_nr in 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 # Make sure the summed amplitude of all channels does not exceed AMPL_MAX
ampl=AMPL_MAX/NOF_CHANNELS ampl=AMPL_MAX/NOF_CHANNELS
# Create the signal in this channel and append to list # 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 ) channel_signals.append( channel_signal )
# Adding all channel sub-signals yields our composite signal # Adding all channel sub-signals yields our composite signal
...@@ -93,29 +103,30 @@ composite_signal=np.sum(channel_signals, axis=0) ...@@ -93,29 +103,30 @@ composite_signal=np.sum(channel_signals, axis=0)
# Plot our composite signal + FFT # Plot our composite signal + FFT
# . This step is optional and not required to overwrite the RAM contents. # . This step is optional and not required to overwrite the RAM contents.
############################################################################### ###############################################################################
# Convert the float values to 8-bit complex if NOPLOT==False:
s_bits = [] # Convert the float values to 8-bit complex
for fword in composite_signal: s_bits = []
re_signed = to_signed(fword.real, COMPLEX_WIDTH) for fword in composite_signal:
im_signed = to_signed(fword.imag, COMPLEX_WIDTH) re_signed = to_signed(fword.real, COMPLEX_WIDTH)
s_bits.append( complex(re_signed, im_signed) ) 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) # Define our axes and plot the signal
t = range(NOF_WORDS_PER_SIGNAL) s = np.array(s_bits)
plt.plot(t, s.real, 'b-', t, s.imag, 'r--') t = range(NOF_WORDS_PER_SIGNAL)
plt.legend(('real', 'imaginary')) plt.plot(t, s.real, 'b-', t, s.imag, 'r--')
plt.show() plt.legend(('real', 'imaginary'))
plt.show()
# Calculate and plot the FFT
yf = fft(s) # Calculate and plot the FFT
xf = fftfreq(NOF_WORDS_PER_SIGNAL, T) yf = fft(s)
xf = range(NOF_WORDS_PER_SIGNAL) xf = fftfreq(NOF_WORDS_PER_SIGNAL, T)
xf = fftshift(xf) xf = range(NOF_WORDS_PER_SIGNAL)
yplot = fftshift(yf) xf = fftshift(xf)
plt.bar(xf, 1.0/NOF_WORDS_PER_SIGNAL * np.abs(yplot)) yplot = fftshift(yf)
plt.grid() plt.bar(xf, 1.0/NOF_WORDS_PER_SIGNAL * np.abs(yplot))
plt.show() plt.grid()
plt.show()
############################################################################### ###############################################################################
# Prepare the data to be written to RAM # Prepare the data to be written to RAM
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment