Added script for plotting the spectrum of signal dumps
This commit is contained in:
parent
a1f62a3b0a
commit
a6fed80149
24
impl/utils/plot_spectrum.py
Executable file
24
impl/utils/plot_spectrum.py
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as pp
|
||||||
|
|
||||||
|
with open(sys.argv[1], 'rb') as infile:
|
||||||
|
header = infile.read(4)
|
||||||
|
if header != b'CPX_':
|
||||||
|
print(f"Error: not a complex signal file. Format {header} not implemented yet.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
T = np.fromfile(infile, dtype=np.float32, count=1)
|
||||||
|
data = np.fromfile(infile, dtype=np.complex64)
|
||||||
|
|
||||||
|
f = np.arange(-1/(2*T), 1/(2*T), 1/T/data.size)
|
||||||
|
|
||||||
|
spec = 20*np.log10(np.absolute(np.fft.fftshift(np.fft.fft(data))) / data.size)
|
||||||
|
|
||||||
|
pp.plot(f, spec, 'b-')
|
||||||
|
pp.legend(['Spectrum'])
|
||||||
|
pp.xlabel('Frequency [Hz]')
|
||||||
|
pp.show()
|
Loading…
Reference in a new issue