@@ -1,5 +1,7 | |||||
1 | import numpy as np |
|
1 | import numpy as np | |
2 |
|
2 | |||
|
3 | from test_fft.register_addresses_fft_test import * | |||
|
4 | ||||
3 | from __main__ import RMAPPlugin0 |
|
5 | from __main__ import RMAPPlugin0 | |
4 |
|
6 | |||
5 | def getWaveFromRecord( cwf, bufferSize, offset, column ): |
|
7 | def getWaveFromRecord( cwf, bufferSize, offset, column ): | |
@@ -18,13 +20,29 def continuous( bufferSize, value ): | |||||
18 | yVector = np.int16( tmpVector ) |
|
20 | yVector = np.int16( tmpVector ) | |
19 | return yVector |
|
21 | return yVector | |
20 |
|
22 | |||
|
23 | def step( bufferSize, value ): | |||
|
24 | tmpVector = np.empty( bufferSize ) | |||
|
25 | for k in range( bufferSize / 2 ): | |||
|
26 | tmpVector[ bufferSize / 2 + k ] = value | |||
|
27 | yVector = np.int16( tmpVector ) | |||
|
28 | return yVector | |||
|
29 | ||||
|
30 | def dirac( bufferSize, value ): | |||
|
31 | tmpVector = np.zeros( bufferSize ) | |||
|
32 | tmpVector[0] = value | |||
|
33 | yVector = np.int16( tmpVector ) | |||
|
34 | return yVector | |||
|
35 | ||||
21 | def generateDataToWrite( bufferSize, wfrm0, wfrm1 ): |
|
36 | def generateDataToWrite( bufferSize, wfrm0, wfrm1 ): | |
22 | dataVector = [] |
|
37 | dataVector = [] | |
23 | for k in range(bufferSize): |
|
38 | for k in range(bufferSize): | |
24 | dataVector.append( ( wfrm1[k] << 16) + wfrm0[k] ) |
|
39 | dataVector.append( | |
|
40 | ( (np.int16(wfrm1[k]) & 0xffff ) << 16) | |||
|
41 | | (np.int16(wfrm0[k]) & 0xffff ) | |||
|
42 | ) | |||
25 | return dataVector |
|
43 | return dataVector | |
26 |
|
44 | |||
27 |
def print_reg_fft( |
|
45 | def print_reg_fft( ): | |
28 | fft_reg = RMAPPlugin0.Read( address_CTRL, 1) |
|
46 | fft_reg = RMAPPlugin0.Read( address_CTRL, 1) | |
29 | out_ren = (fft_reg[0] & 0x0000001f) |
|
47 | out_ren = (fft_reg[0] & 0x0000001f) | |
30 | out_reuse = (fft_reg[0] & 0x000003e0) >> 5 |
|
48 | out_reuse = (fft_reg[0] & 0x000003e0) >> 5 | |
@@ -36,3 +54,26 def print_reg_fft( address_CTRL ): | |||||
36 | + ", out_locked = " + bin( out_locked ) \ |
|
54 | + ", out_locked = " + bin( out_locked ) \ | |
37 | + ", MEM_IN_SM_Full = " + bin( MEM_IN_SM_Full ) \ |
|
55 | + ", MEM_IN_SM_Full = " + bin( MEM_IN_SM_Full ) \ | |
38 | + ", MEM_IN_SM_Empty = " + bin( MEM_IN_SM_Empty ) |
|
56 | + ", MEM_IN_SM_Empty = " + bin( MEM_IN_SM_Empty ) | |
|
57 | RMAPPlugin0.ProcessPendingEvents() | |||
|
58 | ||||
|
59 | def convertToSigned16Bits( dataToConvert ): | |||
|
60 | dataInInt16 = np.int16( dataToConvert ) | |||
|
61 | if dataInInt16 < 32768: | |||
|
62 | val = dataInInt16 | |||
|
63 | else: | |||
|
64 | val = dataInInt16 - 65536 | |||
|
65 | return val | |||
|
66 | ||||
|
67 | def convertVectorToSigned16Bits( bufferSize, dataBuffer ): | |||
|
68 | dataBufferConverted = np.zeros( bufferSize ) | |||
|
69 | for k in range( bufferSize ): | |||
|
70 | dataBufferConverted[k] = convertToSigned16Bits( dataBuffer[k] ) | |||
|
71 | return dataBufferConverted | |||
|
72 | ||||
|
73 | def convertToSigned8Bits( dataToConvert ): | |||
|
74 | dataInInt16 = np.int8( dataToConvert ) | |||
|
75 | if dataInInt16 < 8: | |||
|
76 | val = dataInInt16 | |||
|
77 | else: | |||
|
78 | val = dataInInt16 - 16 | |||
|
79 | return val |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -27,20 +27,24 cwf_f1 = np.genfromtxt( storageDirectory | |||||
27 | ################# |
|
27 | ################# | |
28 | # BUILD WAVEFORMS |
|
28 | # BUILD WAVEFORMS | |
29 | nbSamples = 256 |
|
29 | nbSamples = 256 | |
30 | wfrm0 = continuous( nbSamples, 10 ) |
|
30 | #wfrm0 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnV ) | |
31 |
wfrm1 = |
|
31 | #wfrm1 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnE1 ) | |
32 |
#wfrm2 = getWaveFromRecord( cwf_f1, nbSamples, 0, column |
|
32 | #wfrm2 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnE2 ) | |
33 | wfrm2 = continuous( nbSamples, 1000 ) |
|
33 | #wfrm3 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnB1 ) | |
34 | wfrm3 = continuous( nbSamples, 10000 ) |
|
34 | #wfrm4 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnB2 ) | |
35 | wfrm4 = continuous( nbSamples, 10 ) |
|
35 | wfrm0 = sineWave( 256, 10, 1000 ) | |
|
36 | wfrm1 = dirac( 256, 1000 ) | |||
|
37 | wfrm2 = step( 256, 1000 ) | |||
|
38 | wfrm3 = np.zeros( 256 ) | |||
|
39 | wfrm4 = np.zeros( 256 ) | |||
36 |
|
40 | |||
37 | ################ |
|
41 | ################ | |
38 | # BUILD THE DATA |
|
42 | # BUILD THE DATA | |
39 | dataToWrite0 = generateDataToWrite( nbSamples, wfrm0, wfrm1 ) |
|
43 | dataToWrite0 = generateDataToWrite( nbSamples, wfrm0, wfrm1 ) | |
40 | dataToWrite1 = generateDataToWrite( nbSamples, wfrm2, wfrm3 ) |
|
44 | dataToWrite1 = generateDataToWrite( nbSamples, wfrm2, wfrm3 ) | |
41 |
dataToWrite2 = generateDataToWrite( nbSamples, np.zeros( nbSamples ) |
|
45 | dataToWrite2 = generateDataToWrite( nbSamples, wfrm4, np.zeros( nbSamples ) ) | |
42 |
|
46 | |||
43 |
print_reg_fft( |
|
47 | print_reg_fft( ) | |
44 |
|
48 | |||
45 | # WRITE WAVEFORM IN FIFO |
|
49 | # WRITE WAVEFORM IN FIFO | |
46 | print "write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" |
|
50 | print "write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" | |
@@ -54,7 +58,7 for k in range(nbSamples): | |||||
54 |
|
58 | |||
55 | print "data written in FIFOs" |
|
59 | print "data written in FIFOs" | |
56 |
|
60 | |||
57 |
print_reg_fft( |
|
61 | print_reg_fft( ) | |
58 |
|
62 | |||
59 | # LOCK FIFOs => 0111 1100 0001 1111 |
|
63 | # LOCK FIFOs => 0111 1100 0001 1111 | |
60 | RMAPPlugin0.Write( address_CTRL, [0x00007c1f] ) |
|
64 | RMAPPlugin0.Write( address_CTRL, [0x00007c1f] ) | |
@@ -65,7 +69,7 while (fft_reg[0] & 0x000f8000) == 0: | |||||
65 | print "SM not full" |
|
69 | print "SM not full" | |
66 | fft_reg = RMAPPlugin0.Read( address_CTRL, 1) |
|
70 | fft_reg = RMAPPlugin0.Read( address_CTRL, 1) | |
67 |
|
71 | |||
68 |
print_reg_fft( |
|
72 | print_reg_fft( ) | |
69 |
|
73 | |||
70 | # READ FFT |
|
74 | # READ FFT | |
71 | print "read data in fft FIFOs" |
|
75 | print "read data in fft FIFOs" | |
@@ -80,48 +84,55 fft3_im = np.zeros( nbSamples ) | |||||
80 | fft4_re = np.zeros( nbSamples ) |
|
84 | fft4_re = np.zeros( nbSamples ) | |
81 | fft4_im = np.zeros( nbSamples ) |
|
85 | fft4_im = np.zeros( nbSamples ) | |
82 |
|
86 | |||
83 |
for k in range( |
|
87 | for k in range(128): | |
84 | val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1) |
|
88 | val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1) | |
85 | fft0_re[k] = val[0] & 0xffff |
|
89 | fft0_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) | |
86 | fft0_im[k] = ( val[0] >> 16 ) & 0xffff |
|
90 | fft0_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) | |
87 | val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1) |
|
91 | val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1) | |
88 | fft1_re[k] = val[0] & 0x0000ffff |
|
92 | fft1_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) | |
89 | fft1_im[k] = ( val[0] >> 16 ) & 0xffff |
|
93 | fft1_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) | |
90 | val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1) |
|
94 | val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1) | |
91 | fft2_re[k] = val[0] & 0x0000ffff |
|
95 | fft2_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) | |
92 | fft2_im[k] = ( val[0] >> 16 ) & 0xffff |
|
96 | fft2_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) | |
93 | val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1) |
|
97 | val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1) | |
94 | fft3_re[k] = val[0] & 0x0000ffff |
|
98 | fft3_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) | |
95 | fft3_im[k] = ( val[0] >> 16 ) & 0xffff |
|
99 | fft3_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) | |
96 | val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1) |
|
100 | val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1) | |
97 | fft4_re[k] = val[0] & 0x0000ffff |
|
101 | fft4_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) | |
98 | fft4_im[k] = ( val[0] >> 16 ) & 0xffff |
|
102 | fft4_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) | |
99 | # read enable => 0111 1100 0000 0000 |
|
103 | # read enable => 0111 1100 0000 0000 | |
100 | RMAPPlugin0.Write( address_CTRL, [0x00007c00] ) |
|
104 | RMAPPlugin0.Write( address_CTRL, [0x00007c00] ) | |
101 |
|
105 | |||
|
106 | fft0 = fft0_re * fft0_re + fft0_im * fft0_im | |||
|
107 | fft1 = fft1_re * fft1_re + fft1_im * fft1_im | |||
|
108 | fft2 = fft2_re * fft2_re + fft2_im * fft2_im | |||
|
109 | fft3 = fft3_re * fft3_re + fft3_im * fft3_im | |||
|
110 | fft4 = fft4_re * fft4_re + fft4_im * fft4_im | |||
|
111 | ||||
102 | print "data read in fft FIFOs" |
|
112 | print "data read in fft FIFOs" | |
103 |
|
113 | |||
104 |
print_reg_fft( |
|
114 | print_reg_fft( ) | |
105 |
|
115 | |||
106 | #unlock FIFOs => 0000 0000 0001 1111 |
|
116 | #unlock FIFOs => 0000 0000 0001 1111 | |
107 | RMAPPlugin0.Write( address_CTRL, [0x0000001f] ) |
|
117 | RMAPPlugin0.Write( address_CTRL, [0x0000001f] ) | |
108 |
|
118 | |||
109 |
print_reg_fft( |
|
119 | print_reg_fft( ) | |
110 |
|
120 | |||
111 | # PLOT FFT |
|
121 | # PLOT FFT | |
112 |
|
122 | |||
113 | plt.figure( 1 ) |
|
123 | plt.figure( 1 ) | |
114 | plt.subplot(231) |
|
124 | plt.subplot(231) | |
115 | plt.plot(wfrm0) |
|
125 | plt.plot(wfrm0, 'b') | |
116 | plt.subplot(232) |
|
126 | plt.subplot(232) | |
117 | plt.plot(wfrm1) |
|
127 | plt.plot(wfrm1, 'g') | |
118 | plt.plot(wfrm1, '.') |
|
128 | plt.plot(wfrm1, '.') | |
119 | plt.subplot(233) |
|
129 | plt.subplot(233) | |
120 | plt.plot(wfrm2) |
|
130 | plt.plot(wfrm2, 'r') | |
|
131 | plt.plot(wfrm2, '.') | |||
121 | plt.subplot(234) |
|
132 | plt.subplot(234) | |
122 | plt.plot(wfrm3) |
|
133 | plt.plot(wfrm3, 'c') | |
123 | plt.subplot(235) |
|
134 | plt.subplot(235) | |
124 | plt.plot(wfrm4) |
|
135 | plt.plot(wfrm4, 'm') | |
125 |
|
136 | |||
126 | plt.figure( 2 ) |
|
137 | plt.figure( 2 ) | |
127 | plt.subplot(311) |
|
138 | plt.subplot(311) | |
@@ -145,4 +156,17 plt.plot(fft2_re * fft2_re + fft2_im * f | |||||
145 | plt.plot(fft3_re * fft3_re + fft3_im * fft3_im, 'c') |
|
156 | plt.plot(fft3_re * fft3_re + fft3_im * fft3_im, 'c') | |
146 | plt.plot(fft4_re * fft4_re + fft4_im * fft4_im, 'm') |
|
157 | plt.plot(fft4_re * fft4_re + fft4_im * fft4_im, 'm') | |
147 |
|
158 | |||
|
159 | plt.figure( 3 ) | |||
|
160 | plt.subplot(231) | |||
|
161 | plt.plot(fft0[0:255], 'b') | |||
|
162 | plt.subplot(232) | |||
|
163 | plt.plot(fft1[0:255], 'g') | |||
|
164 | plt.subplot(233) | |||
|
165 | plt.plot(fft2[0:255], 'r') | |||
|
166 | plt.subplot(234) | |||
|
167 | plt.plot(fft3[0:255], 'c') | |||
|
168 | plt.subplot(235) | |||
|
169 | plt.plot(fft4[0:255], 'm') | |||
|
170 | ||||
|
171 | ||||
148 | plt.show() No newline at end of file |
|
172 | plt.show() |
General Comments 0
You need to be logged in to leave comments.
Login now