IQBase
The base class for all other IQ Data
xaratustrah@github Aug-2015
IQBase
Bases: object
Source code in iqtools/iqbase.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
dic2htmlstring(dic)
Converts a dictionary to an HTML string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dic |
dictionary
|
Dictionary of values |
required |
Returns:
Type | Description |
---|---|
string
|
HTML String |
Source code in iqtools/iqbase.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
downsample_and_average(every=2)
Downsampling and averaging in the time domain. This function overrides the data array and also the sampling frequency, allowing further operations to be performed smoothly. If you do not want this behaviour, please make a copy of the object first.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
every |
int
|
Defaults to 2. How many samples to average in time domain. |
2
|
Source code in iqtools/iqbase.py
511 512 513 514 515 516 517 518 519 520 521 |
|
get_broad_peak_dbm(f, p)
staticmethod
Returns the maximum usually useful for a broad peak
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
ndarray of frequencies |
required |
p |
ndarray
|
ndarray of powers |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Coordinates of the peak |
Source code in iqtools/iqbase.py
444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
get_channel_power(f, p, span=None)
Return total power in band in Watts, considering noise bandwidth
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
ndarray of frequencies |
required |
p |
ndarray
|
ndarray of powers |
required |
span |
float
|
Frequency window. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
float
|
Channel power |
Source code in iqtools/iqbase.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
get_dbm(watt)
staticmethod
Convert Watt to dBm
Parameters:
Name | Type | Description | Default |
---|---|---|---|
watt |
float
|
Value in Watts |
required |
Returns:
Type | Description |
---|---|
float
|
Value in dBm |
Source code in iqtools/iqbase.py
458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
get_dp_p_vs_time(xx, yy, zz, eta)
Returns two arrays for plotting dp_p vs time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xx |
ndarray
|
Frequency meshgrid |
required |
yy |
ndarray
|
Time meshgrid |
required |
zz |
ndarray
|
Power meshgrid |
required |
eta |
float
|
description |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Flattened array for 2D plot |
Source code in iqtools/iqbase.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
get_fft(x=None, nframes=0, lframes=0)
Calculate FFT. If nframes and lframes are provided then it Reshapes the data to a 2D matrix, performs FFT in the horizontal direction i.e. for each row, then averages in frequency domain in the vertical direction, for every bin. The result is a flattened 1D array that can be plotted using the frequencies.
Otherwise it is just the standard 1D FFT
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
Complex valued data array. Defaults to None. |
None
|
nframes |
int
|
Number of frames. Defaults to 0. |
0
|
lframes |
int
|
Length of frames. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
tuple
|
Tuple of ndarrays, frequency, power and voltage |
Source code in iqtools/iqbase.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
get_fft_freqs_only(x=None)
Return FFT frequencies only
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
Complex valued data array. Defaults to None, in which |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
Frequency values |
Source code in iqtools/iqbase.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
get_frame_power_vs_time(xx, yy, zz)
Returns two arrays for plotting frame power vs time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xx |
ndarray
|
Frequency meshgrid |
required |
yy |
ndarray
|
Time meshgrid |
required |
zz |
ndarray
|
Power meshgrid |
required |
eta |
float
|
description |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Flattened array for 2D plot |
Source code in iqtools/iqbase.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
get_frame_sum_vs_time(yy, zz)
staticmethod
Return sum of the values in frame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yy |
ndarray
|
Time meshgrid |
required |
zz |
ndarray
|
Power meshgrid |
required |
Returns:
Type | Description |
---|---|
float
|
Sum |
Source code in iqtools/iqbase.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
get_fwhm(f, p, skip=None)
staticmethod
Return the full width at half maximum. f and p are arrays of points corresponding to the original data, whereas the f_peak and p_peak are arrays of containing the coordinates of the peaks only
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
description |
required |
p |
ndarray
|
description |
required |
skip |
int
|
Sometimes peaks have a dip, skip this number of bins, use with care or visual inspection. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
float
|
Full width at half maximum |
Source code in iqtools/iqbase.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
get_narrow_peaks_dbm(f, p, accuracy=50)
staticmethod
Find narrow peaks and return them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
ndarray of frequencies |
required |
p |
ndarray
|
ndarray of powers |
required |
accuracy |
int
|
A number to adjust sensitivity of the peak finder. Defaults to 50. |
50
|
Returns:
Type | Description |
---|---|
ndarray
|
ndarray of peaks and their indexes |
Source code in iqtools/iqbase.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
get_power_spectrogram(nframes, lframes, sparse=False)
Get power spectrogram. Go through the data frame by frame and perform transformation. They can be plotted using pcolormesh x, y and z are ndarrays and have the same shape. In order to access the contents use these kind of indexing as below:
#Slices parallel to frequency axis
nrows = np.shape(x)[0]
for i in range (nrows):
plt.plot(x[i,:], z[i,:])
#Slices parallel to time axis
ncols = np.shape(y)[1]
for i in range (ncols):
plt.plot(y[:,i], z[:, i])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nframes |
int
|
Number of time frames, i.e. rows of matrix |
required |
lframes |
int
|
Number of frequency bins, i.e. number of columns of matrix |
required |
sparse |
bool
|
This will return xx and yy in sparse form which saves a lot of memory. The resulting xx, yy follow the usual broadcasting rules. xx, yy and zz can be plotted directly using matploblib's pcolormesh. |
False
|
Returns:
Type | Description |
---|---|
tuple
|
time, frequency and power as mesh grids |
Source code in iqtools/iqbase.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
get_pwelch(x=None)
Create the power spectral density using Welch method
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
if available the data segment, otherwise the whole data will be taken. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
tuple
|
FFT and power in Watts |
Source code in iqtools/iqbase.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
get_record_length()
Returns the record length
Returns:
Type | Description |
---|---|
float
|
record length |
Source code in iqtools/iqbase.py
101 102 103 104 105 106 107 |
|
get_sigma_estimate(f, p)
staticmethod
Gets an estimate for sigma. Could be used for more precise fitting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
ndarray of frequencies |
required |
p |
ndarray
|
ndarray of powers |
required |
Returns:
Type | Description |
---|---|
float
|
Estimage of sigma |
Source code in iqtools/iqbase.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
get_watt(dbm)
staticmethod
Convert dBm to Watts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dbm |
float
|
Value in dBm |
required |
Returns:
Type | Description |
---|---|
float
|
Value in Watts |
Source code in iqtools/iqbase.py
472 473 474 475 476 477 478 479 480 481 482 |
|
get_window(n=None)
Return a suitable windowing function for FFT
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Window length. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
FFT Window |
Source code in iqtools/iqbase.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
read(nframes, lframes, sframes)
abstractmethod
Abstract method
Source code in iqtools/iqbase.py
109 110 111 112 113 |
|
read_samples(nsamples, offset)
abstractmethod
Abstract method
Source code in iqtools/iqbase.py
115 116 117 118 119 |
|
shift_cut_data_time(x, val)
staticmethod
Handy tool to shift and cut data in time domain
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
Data array |
required |
val |
int
|
Shift index |
required |
Returns:
Type | Description |
---|---|
tuple
|
Shift and cut version |
Source code in iqtools/iqbase.py
541 542 543 544 545 546 547 548 549 550 551 552 |
|
shift_to_center_frequency(f, center)
staticmethod
Just return the shifted frequency to center
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
Array of frequencies |
required |
center |
float
|
Center frequency |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Shifted array of frequencies |
Source code in iqtools/iqbase.py
554 555 556 557 558 559 560 561 562 563 564 565 |
|
zoom_in_freq(f, p, center=0, span=1000)
staticmethod
Cut the frequency domain data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray
|
ndarray of frequencies |
required |
p |
ndarray
|
ndarray of powers |
required |
center |
float
|
Center index. Defaults to 0. |
0
|
span |
float
|
Frequency window. Defaults to 1000. |
1000
|
Returns:
Type | Description |
---|---|
tuple
|
Frequency and power |
Source code in iqtools/iqbase.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
|
pmtm(signal, dpss, axis=-1)
Estimate the power spectral density of the input signal. This function is adopted from this project which was in turn a fork of this project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal |
ndarray
|
n-dimensional array of real or complex values |
required |
dpss |
ndarray
|
The Slepian matrix |
required |
axis |
int
|
Axis along which to apply the Slepian windows. Default is the last one. Defaults to -1. |
-1
|
Returns:
Type | Description |
---|---|
ndarray
|
The multitaper frame, shifted in the correct order |
Source code in iqtools/iqbase.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|