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()