|
|
import os
|
|
|
os.system('clear') # on linux / os x
|
|
|
|
|
|
import numpy as np
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
from test_fft.register_addresses import *
|
|
|
|
|
|
import test_fft.read_flags as flg
|
|
|
import test_fft.data_generator as dtgn
|
|
|
import test_fft.print_custom as prnt
|
|
|
import test_fft.read_data as rdata
|
|
|
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
|
|
|
######################
|
|
|
# GET DATA FROM RECORD
|
|
|
#storageDirectory = '/home/paul/data/2014_06_24/'
|
|
|
#day = '2014_6_24-'
|
|
|
#hour = '9_0_3'
|
|
|
#suffix = '.data'
|
|
|
|
|
|
#typeOfData = '_SBM1_CWF_'
|
|
|
#cwf_f1 = np.genfromtxt( storageDirectory + day + hour + typeOfData + 'F1' + suffix,
|
|
|
# skip_header = 1)
|
|
|
cwf_f1 = np.zeros( 1000 )
|
|
|
|
|
|
#################
|
|
|
# BUILD WAVEFORMS
|
|
|
nbSamples = 256
|
|
|
#wfrm0 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnV )
|
|
|
#wfrm1 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnE1 )
|
|
|
#wfrm2 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnE2 )
|
|
|
#wfrm3 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnB1 )
|
|
|
#wfrm4 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnB2 )
|
|
|
wfrm0 = dtgn.sineWave( nbSamples, 10, 1000 )
|
|
|
wfrm1 = dtgn.dirac( nbSamples, 1000 )
|
|
|
wfrm2 = dtgn.step( nbSamples, 1000 )
|
|
|
wfrm3 = dtgn.continuous( nbSamples, 100 )
|
|
|
wfrm4 = dtgn.continuous( nbSamples, 1000 )
|
|
|
|
|
|
################
|
|
|
# BUILD THE DATA
|
|
|
dataToWrite0 = dtgn.generateDataToWrite( nbSamples, wfrm0, wfrm1 )
|
|
|
dataToWrite1 = dtgn.generateDataToWrite( nbSamples, wfrm2, wfrm3 )
|
|
|
dataToWrite2 = dtgn.generateDataToWrite( nbSamples, wfrm4, np.zeros( nbSamples ) )
|
|
|
|
|
|
########################
|
|
|
# WRITE WAVEFORM IN FIFO
|
|
|
prnt.print_reg_fft( FFT_CTRL )
|
|
|
|
|
|
prnt.print_custom( "1) write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" )
|
|
|
|
|
|
for k in range(nbSamples):
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_1_0, [dataToWrite0[k]] )
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_3_2, [dataToWrite1[k]] )
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_4, [dataToWrite2[k]] )
|
|
|
# write only the FIFO F2
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_WEN, [0xffffffe0] )
|
|
|
|
|
|
prnt.print_custom( "1) data written in FIFOs" )
|
|
|
|
|
|
prnt.print_reg_fft( FFT_CTRL )
|
|
|
|
|
|
# LOCK FIFOs => 0111 1100 0001 1111
|
|
|
RMAPPlugin0.Write( FFT_CTRL, [0x00007c1f] )
|
|
|
|
|
|
# wait for SM_Full
|
|
|
fft_reg = RMAPPlugin0.Read( FFT_CTRL, 1)
|
|
|
counter = 0
|
|
|
while (fft_reg[0] & 0x000f8000) == 0:
|
|
|
prnt.print_custom( "SM not full" )
|
|
|
counter = counter + 1
|
|
|
if counter == 10:
|
|
|
break
|
|
|
fft_reg = RMAPPlugin0.Read( FFT_CTRL, 1)
|
|
|
|
|
|
prnt.print_reg_fft( FFT_CTRL )
|
|
|
|
|
|
################
|
|
|
# FFT FIRST READ
|
|
|
prnt.print_custom( "======= FIRST READ" )
|
|
|
fft0_re = np.zeros( nbSamples )
|
|
|
fft0_im = np.zeros( nbSamples )
|
|
|
fft1_re = np.zeros( nbSamples )
|
|
|
fft1_im = np.zeros( nbSamples )
|
|
|
fft2_re = np.zeros( nbSamples )
|
|
|
fft2_im = np.zeros( nbSamples )
|
|
|
fft3_re = np.zeros( nbSamples )
|
|
|
fft3_im = np.zeros( nbSamples )
|
|
|
fft4_re = np.zeros( nbSamples )
|
|
|
fft4_im = np.zeros( nbSamples )
|
|
|
|
|
|
for k in range(128):
|
|
|
# read enable => 0111 1100 0000 0000
|
|
|
RMAPPlugin0.Write( FFT_CTRL, [0x00007c00] )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_0, 1)
|
|
|
fft0_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft0_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_1, 1)
|
|
|
fft1_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft1_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_2, 1)
|
|
|
fft2_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft2_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_3, 1)
|
|
|
fft3_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft3_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_4, 1)
|
|
|
fft4_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft4_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
if flg.is_MEM_IN_SM_Emty( FFT_CTRL ) == 1:
|
|
|
prnt.print_custom( "k = " + str( k ) )
|
|
|
|
|
|
fft0 = fft0_re * fft0_re + fft0_im * fft0_im
|
|
|
fft1 = fft1_re * fft1_re + fft1_im * fft1_im
|
|
|
fft2 = fft2_re * fft2_re + fft2_im * fft2_im
|
|
|
fft3 = fft3_re * fft3_re + fft3_im * fft3_im
|
|
|
fft4 = fft4_re * fft4_re + fft4_im * fft4_im
|
|
|
|
|
|
#######
|
|
|
# REUSE
|
|
|
prnt.print_custom( "======= REUSE" )
|
|
|
flg.out_locked_AND_out_reuse_AND_out_ren( FFT_CTRL )
|
|
|
prnt.print_reg_fft( FFT_CTRL )
|
|
|
|
|
|
prnt.print_custom( "read data in fft FIFOs" )
|
|
|
fft0_re = np.zeros( nbSamples )
|
|
|
fft0_im = np.zeros( nbSamples )
|
|
|
fft1_re = np.zeros( nbSamples )
|
|
|
fft1_im = np.zeros( nbSamples )
|
|
|
fft2_re = np.zeros( nbSamples )
|
|
|
fft2_im = np.zeros( nbSamples )
|
|
|
fft3_re = np.zeros( nbSamples )
|
|
|
fft3_im = np.zeros( nbSamples )
|
|
|
fft4_re = np.zeros( nbSamples )
|
|
|
fft4_im = np.zeros( nbSamples )
|
|
|
|
|
|
for k in range(128):
|
|
|
# read enable => 0111 1100 0000 0000
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_0, 1)
|
|
|
fft0_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft0_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_1, 1)
|
|
|
fft1_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft1_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_2, 1)
|
|
|
fft2_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft2_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_3, 1)
|
|
|
fft3_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft3_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
val = RMAPPlugin0.Read( FFT_MEM_IN_SM_4, 1)
|
|
|
fft4_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff )
|
|
|
fft4_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
|
|
|
RMAPPlugin0.Write( FFT_CTRL, [0x00007c00] )
|
|
|
if flg.is_MEM_IN_SM_Emty( FFT_CTRL ) == 1:
|
|
|
prnt.print_custom( "k = " + str( k ) )
|
|
|
|
|
|
fft0_b = fft0_re * fft0_re + fft0_im * fft0_im
|
|
|
fft1_b = fft1_re * fft1_re + fft1_im * fft1_im
|
|
|
fft2_b = fft2_re * fft2_re + fft2_im * fft2_im
|
|
|
fft3_b = fft3_re * fft3_re + fft3_im * fft3_im
|
|
|
fft4_b = fft4_re * fft4_re + fft4_im * fft4_im
|
|
|
|
|
|
prnt.print_custom( "data read in fft FIFOs" )
|
|
|
|
|
|
prnt.print_reg_fft( FFT_CTRL )
|
|
|
|
|
|
#unlock FIFOs => 0000 0000 0001 1111
|
|
|
RMAPPlugin0.Write( FFT_CTRL, [0x0000001f] )
|
|
|
|
|
|
prnt.print_reg_fft( FFT_CTRL )
|
|
|
|
|
|
# PLOT FFT
|
|
|
|
|
|
plt.figure( 1 )
|
|
|
plt.subplot(231)
|
|
|
plt.plot(wfrm0, 'b')
|
|
|
plt.subplot(232)
|
|
|
plt.plot(wfrm1, 'g')
|
|
|
plt.plot(wfrm1, '.')
|
|
|
plt.subplot(233)
|
|
|
plt.plot(wfrm2, 'r')
|
|
|
plt.plot(wfrm2, '.')
|
|
|
plt.subplot(234)
|
|
|
plt.plot(wfrm3, 'c')
|
|
|
plt.subplot(235)
|
|
|
plt.plot(wfrm4, 'm')
|
|
|
|
|
|
plt.figure( 2 )
|
|
|
plt.subplot(311)
|
|
|
plt.plot(fft0_re)
|
|
|
plt.plot(fft1_re)
|
|
|
plt.plot(fft2_re)
|
|
|
plt.plot(fft3_re)
|
|
|
plt.plot(fft4_re)
|
|
|
|
|
|
plt.subplot(312)
|
|
|
plt.plot(fft0_im)
|
|
|
plt.plot(fft1_im)
|
|
|
plt.plot(fft2_im)
|
|
|
plt.plot(fft3_im)
|
|
|
plt.plot(fft4_im)
|
|
|
|
|
|
plt.subplot(313)
|
|
|
plt.plot(fft0_re * fft0_re + fft0_im * fft0_im, 'b')
|
|
|
plt.plot(fft1_re * fft1_re + fft1_im * fft1_im, 'g')
|
|
|
plt.plot(fft2_re * fft2_re + fft2_im * fft2_im, 'r')
|
|
|
plt.plot(fft3_re * fft3_re + fft3_im * fft3_im, 'c')
|
|
|
plt.plot(fft4_re * fft4_re + fft4_im * fft4_im, 'm')
|
|
|
|
|
|
plt.figure( 3 )
|
|
|
plt.subplot(231)
|
|
|
plt.plot(fft0[0:255], 'b')
|
|
|
plt.subplot(232)
|
|
|
plt.plot(fft1[0:255], 'g')
|
|
|
plt.subplot(233)
|
|
|
plt.plot(fft2[0:255], 'r')
|
|
|
plt.subplot(234)
|
|
|
plt.plot(fft3[0:255], 'c')
|
|
|
plt.subplot(235)
|
|
|
plt.plot(fft4[0:255], 'm')
|
|
|
|
|
|
plt.figure( 4 )
|
|
|
plt.subplot(231)
|
|
|
plt.plot(fft0_b[0:255], 'b')
|
|
|
plt.subplot(232)
|
|
|
plt.plot(fft1_b[0:255], 'g')
|
|
|
plt.subplot(233)
|
|
|
plt.plot(fft2_b[0:255], 'r')
|
|
|
plt.subplot(234)
|
|
|
plt.plot(fft3_b[0:255], 'c')
|
|
|
plt.subplot(235)
|
|
|
plt.plot(fft4_b[0:255], 'm')
|
|
|
|
|
|
plt.show()
|