From a6fed801495ec0db4114dd97b489bfdf87df68f8 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sat, 29 Jan 2022 22:03:51 +0100 Subject: [PATCH] Added script for plotting the spectrum of signal dumps --- impl/utils/plot_spectrum.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 impl/utils/plot_spectrum.py diff --git a/impl/utils/plot_spectrum.py b/impl/utils/plot_spectrum.py new file mode 100755 index 0000000..16481f6 --- /dev/null +++ b/impl/utils/plot_spectrum.py @@ -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()