Added script for plotting the spectrum of signal dumps

This commit is contained in:
Thomas Kolb 2022-01-29 22:03:51 +01:00
parent a1f62a3b0a
commit a6fed80149
1 changed files with 24 additions and 0 deletions

24
impl/utils/plot_spectrum.py Executable file
View 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()