@@ -1,38 +1,79 | |||||
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 ): | |
6 | yVector = cwf[(0+offset):(bufferSize+offset), column] |
|
8 | yVector = cwf[(0+offset):(bufferSize+offset), column] | |
7 | return yVector |
|
9 | return yVector | |
8 |
|
10 | |||
9 | def sineWave( bufferSize, nbPeriod, amplitude): |
|
11 | def sineWave( bufferSize, nbPeriod, amplitude): | |
10 | deltaX = nbPeriod * 2 * np.pi / bufferSize |
|
12 | deltaX = nbPeriod * 2 * np.pi / bufferSize | |
11 | xVector = np.arange( bufferSize ) * deltaX |
|
13 | xVector = np.arange( bufferSize ) * deltaX | |
12 | yVector = np.int16( amplitude * np.sin( xVector ) ) |
|
14 | yVector = np.int16( amplitude * np.sin( xVector ) ) | |
13 | return yVector |
|
15 | return yVector | |
14 |
|
16 | |||
15 | def continuous( bufferSize, value ): |
|
17 | def continuous( bufferSize, value ): | |
16 | tmpVector = np.empty( bufferSize ) |
|
18 | tmpVector = np.empty( bufferSize ) | |
17 | tmpVector.fill( value ) |
|
19 | tmpVector.fill( 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 | |
31 | out_locked = (fft_reg[0] & 0x00007c00) >> 10 |
|
49 | out_locked = (fft_reg[0] & 0x00007c00) >> 10 | |
32 | MEM_IN_SM_Full = (fft_reg[0] & 0x000f8000) >> 15 |
|
50 | MEM_IN_SM_Full = (fft_reg[0] & 0x000f8000) >> 15 | |
33 | MEM_IN_SM_Empty = (fft_reg[0] & 0x01f00000) >> 20 |
|
51 | MEM_IN_SM_Empty = (fft_reg[0] & 0x01f00000) >> 20 | |
34 | print "out_ren = " + bin( out_ren ) \ |
|
52 | print "out_ren = " + bin( out_ren ) \ | |
35 | + ", out_reuse = " + bin( out_reuse ) \ |
|
53 | + ", out_reuse = " + bin( out_reuse ) \ | |
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 |
@@ -1,148 +1,172 | |||||
1 | import os |
|
1 | import os | |
2 | os.system('clear') # on linux / os x |
|
2 | os.system('clear') # on linux / os x | |
3 |
|
3 | |||
4 | import numpy as np |
|
4 | import numpy as np | |
5 | import matplotlib.pyplot as plt |
|
5 | import matplotlib.pyplot as plt | |
6 |
|
6 | |||
7 | from test_fft.register_addresses_fft_test import * |
|
7 | from test_fft.register_addresses_fft_test import * | |
8 | from test_fft.fft_test_functions import * |
|
8 | from test_fft.fft_test_functions import * | |
9 |
|
9 | |||
10 | print '*' |
|
10 | print '*' | |
11 | print '*' |
|
11 | print '*' | |
12 | print '*' |
|
12 | print '*' | |
13 | print '*' |
|
13 | print '*' | |
14 | print '*' |
|
14 | print '*' | |
15 |
|
15 | |||
16 | ###################### |
|
16 | ###################### | |
17 | # GET DATA FROM RECORD |
|
17 | # GET DATA FROM RECORD | |
18 | storageDirectory = '/home/paul/data/2014_06_24/' |
|
18 | storageDirectory = '/home/paul/data/2014_06_24/' | |
19 | day = '2014_6_24-' |
|
19 | day = '2014_6_24-' | |
20 | hour = '9_0_3' |
|
20 | hour = '9_0_3' | |
21 | suffix = '.data' |
|
21 | suffix = '.data' | |
22 |
|
22 | |||
23 | typeOfData = '_SBM1_CWF_' |
|
23 | typeOfData = '_SBM1_CWF_' | |
24 | cwf_f1 = np.genfromtxt( storageDirectory + day + hour + typeOfData + 'F1' + suffix, |
|
24 | cwf_f1 = np.genfromtxt( storageDirectory + day + hour + typeOfData + 'F1' + suffix, | |
25 | skip_header = 1) |
|
25 | skip_header = 1) | |
26 |
|
26 | |||
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" | |
47 |
|
51 | |||
48 | for k in range(nbSamples): |
|
52 | for k in range(nbSamples): | |
49 | RMAPPlugin0.Write( address_FIFO_F2_1_0, [dataToWrite0[k]] ) |
|
53 | RMAPPlugin0.Write( address_FIFO_F2_1_0, [dataToWrite0[k]] ) | |
50 | RMAPPlugin0.Write( address_FIFO_F2_3_2, [dataToWrite1[k]] ) |
|
54 | RMAPPlugin0.Write( address_FIFO_F2_3_2, [dataToWrite1[k]] ) | |
51 | RMAPPlugin0.Write( address_FIFO_F2_4, [dataToWrite2[k]] ) |
|
55 | RMAPPlugin0.Write( address_FIFO_F2_4, [dataToWrite2[k]] ) | |
52 | # write only the FIFO F2 |
|
56 | # write only the FIFO F2 | |
53 | RMAPPlugin0.Write( address_FIFO_F2_WEN, [0xffffffe0] ) |
|
57 | RMAPPlugin0.Write( address_FIFO_F2_WEN, [0xffffffe0] ) | |
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] ) | |
61 |
|
65 | |||
62 | # wait for SM_Full |
|
66 | # wait for SM_Full | |
63 | fft_reg = RMAPPlugin0.Read( address_CTRL, 1) |
|
67 | fft_reg = RMAPPlugin0.Read( address_CTRL, 1) | |
64 | while (fft_reg[0] & 0x000f8000) == 0: |
|
68 | 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" | |
72 | fft0_re = np.zeros( nbSamples ) |
|
76 | fft0_re = np.zeros( nbSamples ) | |
73 | fft0_im = np.zeros( nbSamples ) |
|
77 | fft0_im = np.zeros( nbSamples ) | |
74 | fft1_re = np.zeros( nbSamples ) |
|
78 | fft1_re = np.zeros( nbSamples ) | |
75 | fft1_im = np.zeros( nbSamples ) |
|
79 | fft1_im = np.zeros( nbSamples ) | |
76 | fft2_re = np.zeros( nbSamples ) |
|
80 | fft2_re = np.zeros( nbSamples ) | |
77 | fft2_im = np.zeros( nbSamples ) |
|
81 | fft2_im = np.zeros( nbSamples ) | |
78 | fft3_re = np.zeros( nbSamples ) |
|
82 | fft3_re = np.zeros( nbSamples ) | |
79 | fft3_im = np.zeros( nbSamples ) |
|
83 | 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) | |
128 | plt.plot(fft0_re) |
|
139 | plt.plot(fft0_re) | |
129 | plt.plot(fft1_re) |
|
140 | plt.plot(fft1_re) | |
130 | plt.plot(fft2_re) |
|
141 | plt.plot(fft2_re) | |
131 | plt.plot(fft3_re) |
|
142 | plt.plot(fft3_re) | |
132 | plt.plot(fft4_re) |
|
143 | plt.plot(fft4_re) | |
133 |
|
144 | |||
134 | plt.subplot(312) |
|
145 | plt.subplot(312) | |
135 | plt.plot(fft0_im) |
|
146 | plt.plot(fft0_im) | |
136 | plt.plot(fft1_im) |
|
147 | plt.plot(fft1_im) | |
137 | plt.plot(fft2_im) |
|
148 | plt.plot(fft2_im) | |
138 | plt.plot(fft3_im) |
|
149 | plt.plot(fft3_im) | |
139 | plt.plot(fft4_im) |
|
150 | plt.plot(fft4_im) | |
140 |
|
151 | |||
141 | plt.subplot(313) |
|
152 | plt.subplot(313) | |
142 | plt.plot(fft0_re * fft0_re + fft0_im * fft0_im, 'b') |
|
153 | plt.plot(fft0_re * fft0_re + fft0_im * fft0_im, 'b') | |
143 | plt.plot(fft1_re * fft1_re + fft1_im * fft1_im, 'g') |
|
154 | plt.plot(fft1_re * fft1_re + fft1_im * fft1_im, 'g') | |
144 | plt.plot(fft2_re * fft2_re + fft2_im * fft2_im, 'r') |
|
155 | plt.plot(fft2_re * fft2_re + fft2_im * fft2_im, 'r') | |
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