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 * from test_fft.test_sm_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 nbComponentsPerMatrix = 15 nbFrequencyBins = 128 #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 = sineWave( 256, 10, 1000 ) wfrm2 = sineWave( 256, 20, 1000 ) wfrm3 = sineWave( 256, 20, 1000 ) wfrm4 = sineWave( 256, 50, 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_sm( ) 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" ) ################ # SM FIRST READ print_custom( "======= SM FIRST READ" ) components = [] wait_for_FIFO_0_or_1_Full() if is_MEM_OUT_SM_Full_FIFO_0( ): address_MEM_OUT_SM = address_MEM_OUT_SM_1 fifo_to_wait_for = 0 elif is_MEM_OUT_SM_Full_FIFO_1( ): address_MEM_OUT_SM = address_MEM_OUT_SM_0 fifo_to_wait_for = 1 for component in range(nbComponentsPerMatrix): print_custom( "==== component = " + str( component ) + ", read @" + hex(address_MEM_OUT_SM & 0xffffffff) ) print_reg_sm( ) currentComp_re = np.zeros( nbFrequencyBins ) currentComp_im = np.zeros( nbFrequencyBins ) if (component == 0) | (component == 12): wait_for_FIFO_Full( fifo_to_wait_for ) currentComp_re = read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) elif (component == 5) | (component == 9): wait_for_FIFO_Full( fifo_to_wait_for ) currentComp_re = read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) elif (component == 1) | (component == 3) | (component == 7): currentComp_re, currentComp_im = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) components.append( currentComp_im ) wait_for_FIFO_Full( fifo_to_wait_for ) elif (component == 2) | (component == 6) | (component == 10): currentComp_re, currentComp_im = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) components.append( currentComp_im ) wait_for_FIFO_Full( fifo_to_wait_for ) elif (component == 4) | (component == 8): currentComp_re, currentComp_im = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) components.append( currentComp_im ) elif (component == 11) | (component == 13): currentComp_re, currentComp_im = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) components.append( currentComp_im ) elif (component == 14): currentComp_re = read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ) components.append( currentComp_re ) else: print_custom( "unexpected value for component" ) # change FIFO if address_MEM_OUT_SM == address_MEM_OUT_SM_0: address_MEM_OUT_SM = address_MEM_OUT_SM_1 fifo_to_wait_for = 0 elif address_MEM_OUT_SM == address_MEM_OUT_SM_1: address_MEM_OUT_SM = address_MEM_OUT_SM_0 fifo_to_wait_for = 1 print_custom( "======= READ COMPLETE" ) print_reg_sm( ) # PLOT SM 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(231) plt.plot(components[0], label='0') plt.plot(components[1], label='1') plt.plot(components[2], label='2') plt.plot(components[3], label='3') plt.legend(loc='upper right') plt.subplot(232) plt.plot(components[4], label='4') plt.plot(components[5], label='5') plt.plot(components[6], label='6') plt.plot(components[7], label='7') plt.legend(loc='upper right') plt.subplot(233) plt.plot(components[8], label='8') plt.plot(components[9], label='9') plt.plot(components[10], label='10') plt.plot(components[11], label='11') plt.legend(loc='upper right') plt.subplot(234) plt.plot(components[12], label='12') plt.plot(components[13], label='13') plt.plot(components[14], label='14') plt.plot(components[15], label='15') plt.legend(loc='upper right') plt.subplot(235) plt.plot(components[16], label='16') plt.plot(components[17], label='17') plt.plot(components[18], label='18') plt.plot(components[19], label='19') plt.legend(loc='upper right') plt.subplot(236) plt.plot(components[20], label='20') plt.plot(components[21], label='21') plt.plot(components[22], label='22') plt.plot(components[23], label='23') plt.plot(components[24], label='24') plt.legend(loc='upper right') plt.show()