From 3fb53cf4310e9a69f8778e12b4afeb8efb19bb2d Mon Sep 17 00:00:00 2001 From: craig-warren Date: Thu, 7 Jan 2016 22:40:57 +0000 Subject: [PATCH] Updated look of plot. Changed power calculation to 10log10 rather than 20log10 as quantity is voltage (or energy) squared. --- tools/plot_builtin_wave.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/plot_builtin_wave.py b/tools/plot_builtin_wave.py index 1401acb0..ff0d06a8 100644 --- a/tools/plot_builtin_wave.py +++ b/tools/plot_builtin_wave.py @@ -51,15 +51,16 @@ while not timeiter.finished: timeiter.iternext() if args.fft: - # Calculate frequency spectra of waveform - power = 20 * np.log10(np.abs(np.fft.fft(waveform))**2) + # Calculate magnitude of frequency spectra of waveform + power = 10 * np.log10(np.abs(np.fft.fft(waveform))**2) freqs = np.fft.fftfreq(power.size, d=dt) - # Shift powers so any spectra with negative DC component will start at zero + # Shift powers so that frequency with maximum power is at zero decibels power -= np.amax(power) # Set plotting range to 4 * centre frequency pltrange = np.where(freqs > (4 * w.freq))[0][0] + pltrange = np.s_[0:pltrange] fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, num=w.type, figsize=(20, 10), facecolor='w', edgecolor='w') @@ -69,7 +70,7 @@ if args.fft: ax1.set_ylabel('Amplitude') # Plot frequency spectra - markerline, stemlines, baseline = ax2.stem(freqs[0:pltrange]/1e9, power[0:pltrange], '--') + markerline, stemlines, baseline = ax2.stem(freqs[pltrange]/1e9, power[pltrange], '--') plt.setp(stemlines, 'color', 'r') plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r') ax2.set_xlabel('Frequency [GHz]')