diff --git a/applications/lofar2/model/rtdsp/plotting.py b/applications/lofar2/model/rtdsp/plotting.py index 83965c17648e3bcc915447f7b3708bea7703690e..3239917635b7c3bced44315a35e961f216f4eae4 100644 --- a/applications/lofar2/model/rtdsp/plotting.py +++ b/applications/lofar2/model/rtdsp/plotting.py @@ -137,7 +137,7 @@ def plot_iir_filter_analysis(b, a, fs=1.0, whole=False, Ntime=100, step=False, l return z, p, k -def plot_spectra(fn, HF, fs=1.0, fLim=None, dbLim=None): +def plot_spectra(fn, HF, fs=1.0, fLim=None, dbLim=None, aLim=None): """Plot spectra for power, magnitude, phase, real, imag Input: @@ -189,6 +189,34 @@ def plot_spectra(fn, HF, fs=1.0, fLim=None, dbLim=None): plt.xlabel(flabel) if fLim: plt.xlim(fLim) + if aLim: + plt.ylim(aLim) + plt.grid(True) + + +def plot_phase_spectrum(fn, HF, fmt='r', fs=1.0, fLim=None, aLim=None): + """Plot phase spectrum + + Use fLim and aLim to zoom in, to see slope in pass band. Note that -pi = + pi. + + Input: + . fn: normalized frequency axis for HF (fs = 1) + . HF: spectrum, e.g. frequency transfer function HF = DTFT(h) + . fmt: curve format string + . fs: sample frequency in Hz + """ + f = fn * fs # scale fn by fs + flabel = 'Frequency [fs = %f]' % fs + + plt.plot(f, np.unwrap(np.angle(HF)), fmt) + plt.title('Phase spectrum') + plt.ylabel('Pase [rad]') + plt.xlabel(flabel) + if fLim: + plt.xlim(fLim) + if aLim: + plt.ylim(aLim) plt.grid(True)