utils: new and improved plotting scripts
This commit is contained in:
parent
a7db93ab9e
commit
b5bae84994
28
impl/utils/plot_amp_phase.py
Executable file
28
impl/utils/plot_amp_phase.py
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/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_':
|
||||
T = np.fromfile(infile, dtype=np.float32, count=1)
|
||||
data = np.fromfile(infile, dtype=np.complex64)
|
||||
else:
|
||||
print(f"Error: Format {header} not implemented yet.")
|
||||
exit(1)
|
||||
|
||||
t = np.arange(0, T*data.size, T)
|
||||
|
||||
amp = np.absolute(data)
|
||||
phase = np.angle(data)
|
||||
|
||||
pp.plot(t, amp, 'r-')
|
||||
pp.legend(['Amplitude'])
|
||||
pp.twinx()
|
||||
pp.plot(t, phase, 'b-')
|
||||
pp.legend(['Phase [radians]'])
|
||||
pp.xlabel('Time [s]')
|
||||
pp.show()
|
44
impl/utils/plot_spectrum_loop.py
Executable file
44
impl/utils/plot_spectrum_loop.py
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as pp
|
||||
|
||||
from matplotlib.animation import FuncAnimation
|
||||
|
||||
def load_data():
|
||||
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)[:data.size]
|
||||
|
||||
spec = 20*np.log10(np.absolute(np.fft.fftshift(np.fft.fft(data))) / data.size)
|
||||
|
||||
return spec, f
|
||||
|
||||
|
||||
fig = pp.figure()
|
||||
ax = pp.subplot()
|
||||
|
||||
spec, f = load_data()
|
||||
|
||||
line, = ax.plot(f, spec, 'b-')
|
||||
|
||||
ax.legend(['Spectrum'])
|
||||
ax.set_xlabel('Frequency [Hz]')
|
||||
|
||||
def update(*args):
|
||||
spec, f = load_data()
|
||||
line.set_ydata(spec)
|
||||
|
||||
return [line]
|
||||
|
||||
anim = FuncAnimation(fig, update, interval=500)
|
||||
pp.show()
|
|
@ -7,13 +7,16 @@ 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.")
|
||||
if header == b'CPX_':
|
||||
T = np.fromfile(infile, dtype=np.float32, count=1)
|
||||
data = np.fromfile(infile, dtype=np.complex64)
|
||||
elif header == b'FLT_':
|
||||
T = np.fromfile(infile, dtype=np.float32, count=1)
|
||||
data = np.fromfile(infile, dtype=np.float32)
|
||||
else:
|
||||
print(f"Error: Format {header} not implemented yet.")
|
||||
exit(1)
|
||||
|
||||
T = np.fromfile(infile, dtype=np.float32, count=1)
|
||||
data = np.fromfile(infile, dtype=np.complex64)
|
||||
|
||||
t = np.arange(0, T*data.size, T)
|
||||
|
||||
pp.plot(t, np.real(data), 'r-')
|
||||
|
|
Loading…
Reference in a new issue