diff --git a/test_fft/fft_test_functions.py b/test_fft/fft_test_functions.py --- a/test_fft/fft_test_functions.py +++ b/test_fft/fft_test_functions.py @@ -1,5 +1,7 @@ import numpy as np +from test_fft.register_addresses_fft_test import * + from __main__ import RMAPPlugin0 def getWaveFromRecord( cwf, bufferSize, offset, column ): @@ -18,13 +20,29 @@ def continuous( bufferSize, value ): yVector = np.int16( tmpVector ) return yVector +def step( bufferSize, value ): + tmpVector = np.empty( bufferSize ) + for k in range( bufferSize / 2 ): + tmpVector[ bufferSize / 2 + k ] = value + yVector = np.int16( tmpVector ) + return yVector + +def dirac( bufferSize, value ): + tmpVector = np.zeros( bufferSize ) + tmpVector[0] = value + yVector = np.int16( tmpVector ) + return yVector + def generateDataToWrite( bufferSize, wfrm0, wfrm1 ): dataVector = [] for k in range(bufferSize): - dataVector.append( ( wfrm1[k] << 16) + wfrm0[k] ) + dataVector.append( + ( (np.int16(wfrm1[k]) & 0xffff ) << 16) + | (np.int16(wfrm0[k]) & 0xffff ) + ) return dataVector -def print_reg_fft( address_CTRL ): +def print_reg_fft( ): fft_reg = RMAPPlugin0.Read( address_CTRL, 1) out_ren = (fft_reg[0] & 0x0000001f) out_reuse = (fft_reg[0] & 0x000003e0) >> 5 @@ -36,3 +54,26 @@ def print_reg_fft( address_CTRL ): + ", out_locked = " + bin( out_locked ) \ + ", MEM_IN_SM_Full = " + bin( MEM_IN_SM_Full ) \ + ", MEM_IN_SM_Empty = " + bin( MEM_IN_SM_Empty ) + RMAPPlugin0.ProcessPendingEvents() + +def convertToSigned16Bits( dataToConvert ): + dataInInt16 = np.int16( dataToConvert ) + if dataInInt16 < 32768: + val = dataInInt16 + else: + val = dataInInt16 - 65536 + return val + +def convertVectorToSigned16Bits( bufferSize, dataBuffer ): + dataBufferConverted = np.zeros( bufferSize ) + for k in range( bufferSize ): + dataBufferConverted[k] = convertToSigned16Bits( dataBuffer[k] ) + return dataBufferConverted + +def convertToSigned8Bits( dataToConvert ): + dataInInt16 = np.int8( dataToConvert ) + if dataInInt16 < 8: + val = dataInInt16 + else: + val = dataInInt16 - 16 + return val diff --git a/test_fft/fft_test_functions.pyc b/test_fft/fft_test_functions.pyc index 1ddac0ea8f4f11ce9171ef0d6d4cee8bc8add781..cceafb0e92dcfd656006e12109459644148d6193 GIT binary patch literal 3450 zc$}?PTTdHD6rS0&jcqQ5U}BP{DXQ{dr74%HiXxSygi8`sAZSfXgcPmJ&KPZ3@0#6N z0+B66qWwdCtknO~pHQh!eWK@_*{&z#+zneUr(zO&}vqXFX3;e&cRgJJ=W$Zbk_FE-CZv}a{Wao z2je_6ysjaLFQMxah_1nEU48l0U|o~740f-VW8EAqfuMI>gkPr)=TIhe&WDyN!}Tz3 zwPe_EKT1`AVbE$tQjzHdUflN82$<(TNk;`?J)0+5gl-||sD-Upmc6n4!^h|~$11Y%R2)YW0(PbhLXb=H#uL`Y~XWe|phLI70mfxXE$0g9su<64V z@viHurKiMI@ukCE8M=W`C48sd@mv)P&7hE;YQ7`d&NOXSA*28Qb63>+ zkVqZ|M^q%rX81IJz#Su@%t&clz?~9bnxUS7ydYs5hdiSS@0mzog92}-j?-8;IgudS z9d)kI*K$42!j<(CX8Ocw(~BkXpxT`w0xnYs`pWg=AdaT4AXoS}G=iK@8bN-06Y|+( zJY$_EGvHc(KTBvSTM{=wuPvX9|Zp45zKn5Kiyj1G5oo z1IqI3`<{_`3g8(5kC}Oj;3}SzA<34xzN*B)ehYz>Qr9E!RKVIF-JNsL)XLz&Hry5!uP+NoKQs zs}z>rvO-vcyH%9|7j5*mfjAB?bwWUZo5Sb6#;GPL1n=+(X!Og!<_=FnFsn-6T$d)E z)b?W#(?@7S)cIv{8f;b`4Q z-4;JepQD%93mWc`FU8W+RaZsd^^5ZuFB#=4an3$xUfdMtvwBjbNX+h|zUlmdG(oNE z(nsC$$pcU-<7Sz*?x#v+Eet4irb4UqiAM@@HB4BNVkqkL*%c{T^9HF|>lgQF(5NAY z22QPII|~g;L5R|4x~5@Kv@lYw`60lq-i(1~h;#F12-GWSk?`Yo=Und%RXbf`9@5B# z;vU+GPRPhkSEa8$+io{q-?m9vEK~yv#n8Ho-97A(eQOT8uhKBEkWcH|0j#(D`dn@Y gBKG79+(v{!GiH>HNu!i272r1ltyG#Q6-$MG0mT5NeE3_<{mV2ptqeNopaTyg-PMDFi2f7=HPC+GI~l@n3!yUH=^#4kBD#`p zts7`2oU+>4WuATJo#ACz#{I};@bW$!VfHv`9I6q%DKJ2a4#)w=Kryfja=~#>9Gn0p zz)4UNoC2l5X;2!x09pWNKpF5NXc3$RWx+X64!i_f0_Q<_Z~;^R7ePhvGH4lG0+qmJ zP#L@eS^=+uR>5naHE;#P>bg2u2YI~e<96ak(nhjI3P#FCDn>SpY#P}zQZ=$|q;8~X zWY@^PkwYV=Ga2h2IgV+#8gY$;MpB_)ttiTp!Zq_W2t(2Cw9iDlE<90>%p1a&#fZEa zx%;ZskH|esyJuHgtTroX-A%}@Nf$?^Qk@voIeRbPxBgnJ6L$)l`w+XK<+U38Dm&jvLa zgi_qx$l5fx9fvZQirImJP{%^A?>s(#HSga~_~|Y<(Dy9dQAj#pZ_M)5=6<{L2@ts0 At^fc4 diff --git a/test_fft/test_fft_mini_lfr.py b/test_fft/test_fft_mini_lfr.py --- a/test_fft/test_fft_mini_lfr.py +++ b/test_fft/test_fft_mini_lfr.py @@ -27,20 +27,24 @@ cwf_f1 = np.genfromtxt( storageDirectory ################# # 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 ) +#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 = np.zeros( 256 ) +wfrm4 = np.zeros( 256 ) ################ # BUILD THE DATA dataToWrite0 = generateDataToWrite( nbSamples, wfrm0, wfrm1 ) dataToWrite1 = generateDataToWrite( nbSamples, wfrm2, wfrm3 ) -dataToWrite2 = generateDataToWrite( nbSamples, np.zeros( nbSamples ), wfrm4 ) +dataToWrite2 = generateDataToWrite( nbSamples, wfrm4, np.zeros( nbSamples ) ) -print_reg_fft( address_CTRL ) +print_reg_fft( ) # WRITE WAVEFORM IN FIFO print "write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" @@ -54,7 +58,7 @@ for k in range(nbSamples): print "data written in FIFOs" -print_reg_fft( address_CTRL ) +print_reg_fft( ) # LOCK FIFOs => 0111 1100 0001 1111 RMAPPlugin0.Write( address_CTRL, [0x00007c1f] ) @@ -65,7 +69,7 @@ while (fft_reg[0] & 0x000f8000) == 0: print "SM not full" fft_reg = RMAPPlugin0.Read( address_CTRL, 1) -print_reg_fft( address_CTRL ) +print_reg_fft( ) # READ FFT print "read data in fft FIFOs" @@ -80,48 +84,55 @@ fft3_im = np.zeros( nbSamples ) fft4_re = np.zeros( nbSamples ) fft4_im = np.zeros( nbSamples ) -for k in range(nbSamples): +for k in range(128): val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1) - fft0_re[k] = val[0] & 0xffff - fft0_im[k] = ( val[0] >> 16 ) & 0xffff + 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] = val[0] & 0x0000ffff - fft1_im[k] = ( val[0] >> 16 ) & 0xffff + 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] = val[0] & 0x0000ffff - fft2_im[k] = ( val[0] >> 16 ) & 0xffff + 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] = val[0] & 0x0000ffff - fft3_im[k] = ( val[0] >> 16 ) & 0xffff + 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] = val[0] & 0x0000ffff - fft4_im[k] = ( val[0] >> 16 ) & 0xffff + fft4_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) + fft4_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) # read enable => 0111 1100 0000 0000 RMAPPlugin0.Write( address_CTRL, [0x00007c00] ) +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 + print "data read in fft FIFOs" -print_reg_fft( address_CTRL ) +print_reg_fft( ) #unlock FIFOs => 0000 0000 0001 1111 RMAPPlugin0.Write( address_CTRL, [0x0000001f] ) -print_reg_fft( address_CTRL ) +print_reg_fft( ) # PLOT FFT plt.figure( 1 ) plt.subplot(231) -plt.plot(wfrm0) +plt.plot(wfrm0, 'b') plt.subplot(232) -plt.plot(wfrm1) +plt.plot(wfrm1, 'g') plt.plot(wfrm1, '.') plt.subplot(233) -plt.plot(wfrm2) +plt.plot(wfrm2, 'r') +plt.plot(wfrm2, '.') plt.subplot(234) -plt.plot(wfrm3) +plt.plot(wfrm3, 'c') plt.subplot(235) -plt.plot(wfrm4) +plt.plot(wfrm4, 'm') plt.figure( 2 ) plt.subplot(311) @@ -145,4 +156,17 @@ plt.plot(fft2_re * fft2_re + fft2_im * f 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.show() \ No newline at end of file