##// END OF EJS Templates
test_fft directory added to the repository
test_fft directory added to the repository

File last commit:

r4:a2755b43b4c9 default
r4:a2755b43b4c9 default
Show More
test_fft_mini_lfr.py
147 lines | 3.8 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 '*'
print '*'
print '*'
print '*'
print '*'
######################
# 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)
#################
# BUILD WAVEFORMS
nbSamples = 256
wfrm0 = continuous( nbSamples, 10 )
wfrm1 = sineWave( nbSamples, 2, 1000)
#wfrm2 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnV )
wfrm2 = continuous( nbSamples, 1000 )
wfrm3 = continuous( nbSamples, 10000 )
wfrm4 = continuous( nbSamples, 10 )
################
# BUILD THE DATA
dataToWrite0 = generateDataToWrite( nbSamples, wfrm0, wfrm1 )
dataToWrite1 = generateDataToWrite( nbSamples, wfrm2, wfrm3 )
dataToWrite2 = generateDataToWrite( nbSamples, np.zeros( nbSamples ), wfrm4 )
print_reg_fft( address_CTRL )
# WRITE WAVEFORM IN FIFO
print "write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples"
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 "data written in FIFOs"
print_reg_fft( address_CTRL )
# 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 "SM not full"
fft_reg = RMAPPlugin0.Read( address_CTRL, 1)
print_reg_fft( address_CTRL )
# READ FFT
print "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(nbSamples):
val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1)
fft0_re[k] = val[0] & 0xffff
fft0_im[k] = ( val[0] >> 16 ) & 0xffff
val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1)
fft1_re[k] = val[0] & 0x0000ffff
fft1_im[k] = ( val[0] >> 16 ) & 0xffff
val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1)
fft2_re[k] = val[0] & 0x0000ffff
fft2_im[k] = ( val[0] >> 16 ) & 0xffff
val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1)
fft3_re[k] = val[0] & 0x0000ffff
fft3_im[k] = ( val[0] >> 16 ) & 0xffff
val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1)
fft4_re[k] = val[0] & 0x0000ffff
fft4_im[k] = ( val[0] >> 16 ) & 0xffff
# read enable => 0111 1100 0000 0000
RMAPPlugin0.Write( address_CTRL, [0x00007c00] )
print "data read in fft FIFOs"
print_reg_fft( address_CTRL )
#unlock FIFOs => 0000 0000 0001 1111
RMAPPlugin0.Write( address_CTRL, [0x0000001f] )
print_reg_fft( address_CTRL )
# PLOT FFT
plt.figure( 1 )
plt.subplot(231)
plt.plot(wfrm0)
plt.subplot(232)
plt.plot(wfrm1)
plt.plot(wfrm1, '.')
plt.subplot(233)
plt.plot(wfrm2)
plt.subplot(234)
plt.plot(wfrm3)
plt.subplot(235)
plt.plot(wfrm4)
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.show()