@@ -93,8 +93,8 @@ def sweep_callback(object device, cnp.ndarray[cnp.int8_t, ndim=1] buffer, int bu
9393
9494 cdef uint64_t start_frequency = current_device_data[' start_frequency' ]
9595
96- cdef cnp.ndarray fftwOut
97- cdef cnp.ndarray dbph
96+ cdef cnp.ndarray fftOut
97+ cdef cnp.ndarray pwr
9898
9999 cdef uint32_t fft_1_start = 1 + (fft_size * 5 ) // 8
100100 cdef uint32_t fft_1_stop = 1 + (fft_size * 5 ) // 8 + fft_size // 4
@@ -137,11 +137,11 @@ def sweep_callback(object device, cnp.ndarray[cnp.int8_t, ndim=1] buffer, int bu
137137
138138 index += (pyhackrf.PY_BYTES_PER_BLOCK - data_length)
139139
140- fftwOut = fft((buffer [index:index + data_length:2 ] / 128 + 1j * buffer [index + 1 :index + data_length:2 ] / 128 ) * window)
141- dbph = np.log10(np.abs(fftwOut) ** 2 * norm_factor ) * 10.0
140+ fftOut = fft((buffer [index:index + data_length:2 ] / 128 + 1j * buffer [index + 1 :index + data_length:2 ] / 128 ) * window)
141+ pwr = np.log10(np.abs(fftOut * norm_factor) ** 2 ) * 10.0
142142
143143 if sweep_style == pyhackrf.py_sweep_style.LINEAR:
144- dbph = fftshift(dbph )
144+ pwr = fftshift(pwr )
145145
146146 index += data_length
147147
@@ -151,18 +151,18 @@ def sweep_callback(object device, cnp.ndarray[cnp.int8_t, ndim=1] buffer, int bu
151151 line = struct .pack(' I' , record_length)
152152 line += struct .pack(' Q' , frequency)
153153 line += struct .pack(' Q' , frequency + sample_rate // 4 )
154- line += struct .pack(' <' + ' f' * (fft_size // 4 ), * dbph [fft_1_start:fft_1_stop])
154+ line += struct .pack(' <' + ' f' * (fft_size // 4 ), * pwr [fft_1_start:fft_1_stop])
155155 line += struct .pack(' I' , record_length)
156156 line += struct .pack(' Q' , frequency + sample_rate // 2 )
157157 line += struct .pack(' Q' , frequency + (sample_rate * 3 ) // 4 )
158- line += struct .pack(' <' + ' f' * (fft_size // 4 ), * dbph [fft_2_start:fft_2_stop])
158+ line += struct .pack(' <' + ' f' * (fft_size // 4 ), * pwr [fft_2_start:fft_2_stop])
159159
160160 else :
161161 record_length = 16 + fft_size * 4
162162 line = struct .pack(' I' , record_length)
163163 line += struct .pack(' Q' , frequency)
164164 line += struct .pack(' Q' , frequency + sample_rate)
165- line += struct .pack(' <' + ' f' * fft_size, * dbph )
165+ line += struct .pack(' <' + ' f' * fft_size, * pwr )
166166
167167 current_device_data[' file' ].write(line)
168168
@@ -172,39 +172,37 @@ def sweep_callback(object device, cnp.ndarray[cnp.int8_t, ndim=1] buffer, int bu
172172 ' timestamp' : time_str,
173173 ' start_frequency' : frequency,
174174 ' stop_frequency' : frequency + sample_rate // 4 ,
175- ' array' : dbph [fft_1_start:fft_1_stop]
175+ ' array' : pwr [fft_1_start:fft_1_stop]
176176 })
177177 current_device_data[' queue' ].put({
178178 ' timestamp' : time_str,
179179 ' start_frequency' : frequency + sample_rate // 2 ,
180180 ' stop_frequency' : frequency + (sample_rate * 3 ) // 4 ,
181- ' array' : dbph [fft_2_start:fft_2_stop]
181+ ' array' : pwr [fft_2_start:fft_2_stop]
182182 })
183183
184184 else :
185185 current_device_data[' queue' ].put({
186186 ' timestamp' : time_str,
187187 ' start_frequency' : frequency,
188188 ' stop_frequency' : frequency + sample_rate,
189- ' array' : dbph
189+ ' array' : pwr
190190 })
191191
192192 else :
193193 if sweep_style == pyhackrf.py_sweep_style.INTERLEAVED:
194194 line = f' {time_str}, {frequency}, {frequency + sample_rate // 4}, {sample_rate / fft_size}, {fft_size}, '
195- dbph_1 = dbph[fft_1_start:fft_1_stop]
196- for i in range (len (dbph_1)):
197- line += f' {dbph_1[i]:.10f}, '
195+ for value in pwr[fft_1_start:fft_1_stop]:
196+ line += f' {value:.10f}, '
198197 line += f' \n {time_str}, {frequency + sample_rate // 2}, {frequency + (sample_rate * 3) // 4}, {sample_rate / fft_size}, {fft_size}, '
199- dbph_2 = dbph[fft_2_start:fft_2_stop]
200- for i in range (len (dbph_2)):
201- line += f' {dbph_2[i]:.10f}, '
198+ for value in pwr[fft_2_start:fft_2_stop]:
199+ line += f' {value:.10f}, '
202200 line = line[:len (line) - 2 ] + ' \n '
203201
204202 else :
205203 line = f' {time_str}, {frequency}, {frequency + sample_rate}, {sample_rate / fft_size}, {fft_size}, '
206- for i in range (len (dbph )):
207- line += f' {dbph [i]:.2f}, '
204+ for i in range (len (pwr )):
205+ line += f' {pwr [i]:.2f}, '
208206 line = line[:len (line) - 2 ] + ' \n '
209207
210208 current_device_data[' file' ].write(line)
0 commit comments