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

-Fixed re/im concatenation swap;

-Now splitting the correlator output list into nof_visibilities-sized packets.
parent 9c7e85cd
No related branches found
No related tags found
No related merge requests found
......@@ -19,8 +19,8 @@
#
###############################################################################
from common import *
import matplotlib
matplotlib.use('TkAgg')
#import matplotlib
#matplotlib.use('TkAgg')
from common_dsp import *
from mem_init_file import list_to_hex
......@@ -54,7 +54,7 @@ CORRELATOR_OUTPUT_COMPLEX_WIDTH = CORRELATOR_MULT_OUTPUT_COMPLEX_WIDTH + ceil_lo
NOF_WORDS_PER_BLOCK = NOF_CHANNELS*pow(2, NOF_FOLDS)
MEM_WIDTH = COMPLEX_WIDTH*2
MEM_DEPTH = NOF_WORDS_PER_BLOCK
PATH = "../hex"
PATH = "../../src/hex"
FILENAME = "complex_subbands"
......@@ -100,7 +100,7 @@ def complex_to_int(input_lists):
print 'Input', input_nr, 'Channel', word, 're,im', re, im
re_bits = CommonBits(re, COMPLEX_WIDTH)
im_bits = CommonBits(im, COMPLEX_WIDTH)
concat_bits = re_bits & im_bits
concat_bits = im_bits & re_bits
output_list.append(concat_bits.data)
output_lists.append(output_list)
......@@ -149,6 +149,7 @@ def correlate(input_lists, accumulation_factor):
# Feed each channel to the correlation function
vis_per_channel = []
for inputs in inputs_per_channel:
vis = complex_matrix_corr(inputs, inputs, 'complex', conjugate=True)
# complex_matrix_corr() returns a full matrix of nof_inputs*nof_inputs.
......@@ -167,26 +168,11 @@ def correlate(input_lists, accumulation_factor):
vis_per_channel.append( unique_vis_per_channel_int_acc )
return vis_per_channel
REC_FILE = os.environ['RADIOHDL']+'/libraries/dsp/correlator/tb/rec/correlator_src_out_arr0.rec'
def rec_file_to_list(filename, field_indices=range(11)):
"""
Read a .rec file written by dp_stream_recorder.vhd and return the contents
as strings in a Python list.
Every line in the file has 11 space-seperated fields:
0 1 2 3 4 5 6 7 8 9 10
[sync] [bsn] [data] [re] [im] [valid] [sop] [eop] [empty] [channel] [err]
A list of length 0..nof_lines-1 is returned for each field passed in
field_indices.
"""
NOF_DP_RECORD_FIELDS = 11
DP_RECORD_INDEX_SYNC = 0
......@@ -201,6 +187,22 @@ def rec_file_to_list(filename, field_indices=range(11)):
DP_RECORD_INDEX_CHANNEL = 9
DP_RECORD_INDEX_ERR = 10
def rec_file_to_list(filename, field_indices=range(11)):
"""
Read a .rec file written by dp_stream_recorder.vhd and return the contents
as strings in a Python list.
Every line in the file has 11 space-seperated fields:
0 1 2 3 4 5 6 7 8 9 10
[sync] [bsn] [data] [re] [im] [valid] [sop] [eop] [empty] [channel] [err]
A list of length 0..nof_lines-1 is returned for each field passed in
field_indices.
"""
fields_sync = []
fields_bsn = []
fields_data = []
......@@ -245,19 +247,28 @@ def rec_file_to_complex(filename, complex_width):
"""
Read from a .rec file and extract the complex fields.
Returns complex format.
Set packetize to True to re-shape the list into packet-sized (as tagged
by SOP and EOP) sublists.
The complex_list is re-shaped into packet-sized (as tagged by SOP and EOP)
sublists.
"""
re_im_strings = rec_file_to_list(filename, [3,4])
# Read REC file and extract re,im,EOP fields.
re_im_eop_strings = rec_file_to_list(filename, [DP_RECORD_INDEX_RE,DP_RECORD_INDEX_IM,DP_RECORD_INDEX_EOP])
complex_list = []
for re_str,im_str in zip(re_im_strings[0], re_im_strings[1]):
# Convert re,im strings to complex format
for re_str,im_str in zip(re_im_eop_strings[0], re_im_eop_strings[1]):
re = to_signed(int(re_str, 16), complex_width)
im = to_signed(int(im_str, 16), complex_width)
# Convert integers to complex
complex_list.append( complex(re,im) )
return complex_list
# Figure out the packet size based on EOP
for word_nr,eop in enumerate(re_im_eop_strings[2]):
if eop == '1':
packet_size=word_nr+1
break
# Split the complex_list into packet_size chunks and return the result.
return split_list(complex_list, packet_size)
# Generate input data
correlator_snk_in_arr_complex = gen_complex_inputs(NOF_INPUTS, NOF_CHANNELS, COMPLEX_WIDTH)
......@@ -265,7 +276,7 @@ correlator_snk_in_arr_complex = gen_complex_inputs(NOF_INPUTS, NOF_CHANNELS, COM
# Convert to int and generate HEX files from input data
correlator_snk_in_arr_int = complex_to_int(correlator_snk_in_arr_complex)
#gen_correlator_snk_in_arr_hex(correlator_snk_in_arr_int)
gen_correlator_snk_in_arr_hex(correlator_snk_in_arr_int)
# Calculate correlator output from input lists
correlator_src_out_arr_ref = correlate(correlator_snk_in_arr_complex, INTEGRATION_PERIOD)
......@@ -277,8 +288,13 @@ correlator_src_out_arr_ref = correlate(correlator_snk_in_arr_complex, INTEGRATIO
# Read test bench output file written by dp_stream_rec_play.vhd
correlator_src_out_arr = rec_file_to_complex(REC_FILE, complex_width=CORRELATOR_OUTPUT_COMPLEX_WIDTH)
print correlator_src_out_arr[0:21]
print correlator_src_out_arr_ref[0][0:21]
print 'corr out', correlator_src_out_arr[0]
print 'corr ref', correlator_src_out_arr_ref[0]
def plot_phase_shifts(correlator_output):
"""
......@@ -300,10 +316,10 @@ def plot_phase_shifts(correlator_output):
# Split the list into chunks of nof_visibilities, plot them channel after channel
################################################################################
phases_per_channel = split_list(phases, NOF_VISIBILITIES)
for channel_phases in phases_per_channel:
phases_mat = numpy.array(channel_phases)
mat = unique_vis_to_full_matrix(phases_mat)
plot_matrix_color([[mat]])
plot_phase_shifts(correlator_src_out_arr_ref[0]) # NOTE THE INVERTED PHASES !!!!!!!!!!!!!!!!!!
plot_phase_shifts(correlator_src_out_arr[0])
plot_phase_shifts(correlator_src_out_arr_ref[0])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment