##// END OF EJS Templates
Sync
Sync

File last commit:

r7:565b8186dcb8 default
r8:80993ec2f9f2 default
Show More
test_fft_mini_lfr.py
231 lines | 7.0 KiB | text/x-python | PythonLexer
import os
os.system('clear') # on linux / os x
import numpy as np
import matplotlib.pyplot as plt
from test_fft.register_addresses_fft_test import *
from test_fft.fft_test_functions import *
print_custom( '*' )
print_custom( '*' )
print_custom( '*' )
print_custom( '*' )
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 = sineWave( 256, 10, 1000 )
wfrm1 = dirac( 256, 1000 )
wfrm2 = step( 256, 1000 )
wfrm3 = continuous( 256, 100 )
wfrm4 = continuous( 256, 1000 )
################
# BUILD THE DATA
dataToWrite0 = generateDataToWrite( nbSamples, wfrm0, wfrm1 )
dataToWrite1 = generateDataToWrite( nbSamples, wfrm2, wfrm3 )
dataToWrite2 = generateDataToWrite( nbSamples, wfrm4, np.zeros( nbSamples ) )
########################
# WRITE WAVEFORM IN FIFO
print_custom( "1) write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" )
print_reg_fft( )
for k in range(nbSamples):
RMAPPlugin0.Write( address_FIFO_F2_1_0, [dataToWrite0[k]] )
RMAPPlugin0.Write( address_FIFO_F2_3_2, [dataToWrite1[k]] )
RMAPPlugin0.Write( address_FIFO_F2_4, [dataToWrite2[k]] )
# write only the FIFO F2
RMAPPlugin0.Write( address_FIFO_F2_WEN, [0xffffffe0] )
print_custom( "1) data written in FIFOs" )
print_reg_fft( )
# LOCK FIFOs => 0111 1100 0001 1111
RMAPPlugin0.Write( address_CTRL, [0x00007c1f] )
# wait for SM_Full
fft_reg = RMAPPlugin0.Read( address_CTRL, 1)
while (fft_reg[0] & 0x000f8000) == 0:
print_custom( "SM not full" )
fft_reg = RMAPPlugin0.Read( address_CTRL, 1)
print_reg_fft( )
################
# FFT FIRST READ
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( address_CTRL, [0x00007c00] )
val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1)
fft0_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft0_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1)
fft1_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft1_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1)
fft2_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft2_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1)
fft3_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft3_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1)
fft4_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft4_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
if is_MEM_IN_SM_Emty( ) == 1:
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
print_custom( "======= REUSE" )
out_locked_AND_out_reuse_AND_out_ren()
print_reg_fft( )
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( address_MEM_IN_SM_0, 1)
fft0_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft0_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1)
fft1_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft1_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1)
fft2_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft2_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1)
fft3_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft3_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1)
fft4_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff )
fft4_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) )
RMAPPlugin0.Write( address_CTRL, [0x00007c00] )
if is_MEM_IN_SM_Emty( ) == 1:
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
print_custom( "data read in fft FIFOs" )
print_reg_fft( )
#unlock FIFOs => 0000 0000 0001 1111
RMAPPlugin0.Write( address_CTRL, [0x0000001f] )
print_reg_fft( )
# 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()