Some improvements in the scope functions and waveform handling

Include toolbar icons
parent cbfc69b8
......@@ -29,7 +29,7 @@ from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
# NOTE: there are some 0.94 ~ 0.98 factors: these are scaling the input to <1
from scope import *
class Generator:
......@@ -50,7 +50,7 @@ class Generator:
def waveform(self):
def generate_stimulus(self):
'''This method returns a parametrized waveform signal:
* waveform: assign signal geometry, with valid values:
[doppler, chirp, sawtooth, square, gausspulse, sweep]
......@@ -134,28 +134,31 @@ class Generator:
# clear the axes and redraw the plot anew
#
self.axes.clear()
self.axes.grid(self.cbGridStimulus.isChecked())
grid = self.cbGridStimulus.isChecked()
self.x = self.generate_stimulus()
print('Generate a basic signal using the generator')
print(self.comboWaveform.currentText())
self.x = self.waveform()
self.axes.plot(self.x, 'go-', label='Channel 1')
self.axes.set_ylabel('value')
self.axes.set_xlabel('sample')
stimulusWave = Waveform(value = self.x,
label = 'Stimulus',
color = '#00ff00')
scopeTime(self.figStimulus, [stimulusWave], grid)
self.canvasStimulus.draw()
self.stimulusUpdatedSignal.emit()
def create_stimulus_layout(self):
# Create the mpl Figure and FigCanvas objects.
# 5x4 inches, 100 dots-per-inch
#
self.dpi = 100
self.fig = Figure((5.0, 4.0), dpi=self.dpi)
self.canvasStimulus = FigureCanvas(self.fig)
#self.dpi = 100
#self.fig = Figure((5.0, 4.0), dpi=self.dpi)
self.figStimulus = Figure()
self.canvasStimulus = FigureCanvas(self.figStimulus)
self.canvasStimulus.setParent(self.main_frame)
# Since we have only one plot, we can use add_axes
......@@ -163,7 +166,7 @@ class Generator:
# configuration tool in the navigation toolbar wouldn't
# work.
#
self.axes = self.fig.add_subplot(111)
#self.axes = self.fig.add_subplot(111)
# Bind the 'pick' event for clicking on one of the bars
#
......
......@@ -32,6 +32,17 @@ import sys, os, random
'''
class Waveform:
def __init__(self, value=[0], label='waveform', color='#000000',
linestyle='-', marker='o', markersize=8):
self.value = value
self.label = label
self.color = color
self.linestyle = linestyle
self.marker = marker
self.markersize = markersize
def analyze_pole_zero(figure, b, a, p, q, grid):
......@@ -228,53 +239,58 @@ def analyze_frequency_response(figure, b, a, p, q, grid):
phaseSubplot.set_title(r'Phase response (Float=Blue; Int=Error)')
return True, 'OK'
def scopeDual(figure, s1, s2, grid):
def scopeTime(figure, waveform, grid):
'''this method shows a dual time domain scope:
* s1: channel-1 input signal (blue, float)
* s2: channel-2 input signal (red, int)
'''
'''
# Simulate float system response:
print('Run Scope Dual')
print('len(s1) =', len(s1))
print('len(s2) =', len(s2))
print('Run Scope Time')
figure.clear()
scopeTimeSubplot = figure.add_subplot(111)
scopeTimeSubplot.set_ylabel('Value')
scopeTimeSubplot.set_xlabel('Sample')
scopeTimeSubplot.set_title(r'Time Scope')
scopeTimeSubplot.grid(grid)
for ii in range(len(waveform)):
scopeTimeSubplot.plot(waveform[ii].value,
color = waveform[ii].color,
label = waveform[ii].label,
linestyle = waveform[ii].linestyle,
marker = waveform[ii].marker,
markersize = waveform[ii].markersize)
scopeTimeSubplot.plot(s1, 'bo-', label='Float')
scopeTimeSubplot.plot(s2, 'ro-', label='Hardware')
#self.scopeTimeSublot.axis('scaled')
#scopeTimeSubplot.set_title(r'Time Scope (red: int, blue: float)')
scopeTimeSubplot.set_ylabel('value')
scopeTimeSubplot.set_xlabel('sample')
scopeTimeSubplot.legend().draggable(state=True, use_blit=True)
scopeTimeSubplot.grid(grid)
def scopePower(figure, s1, s2, grid):
def scopePower(figure, waveform, grid):
'''this method shows the estimated power spectrum for a signal:
* s: channel-1 assigned signal (blue)
'''
print('Plotting Power Spectrum...')
Ps1,fs1 = mlab.psd(s1)
Ps2,fs2 = mlab.psd(s2)
figure.clear()
scopePowerSubplot = figure.add_subplot(111)
scopePowerSubplot.plot(fs1, 10*log10(abs(Ps1)), 'b')
scopePowerSubplot.plot(fs2, 10*log10(abs(Ps2)), 'r')
scopePowerSubplot.set_ylabel('Power (dB)')
scopePowerSubplot.set_xlabel('Normalized Frequency')
scopePowerSubplot.set_title(r'Signal Power (red: int, blue: float)')
scopePowerSubplot.set_title(r'Signal Power')
scopePowerSubplot.grid(grid)
for ii in range(len(waveform)):
Ps,fs = mlab.psd(waveform[ii].value)
scopePowerSubplot.plot(fs, 10*log10(abs(Ps)),
color = waveform[ii].color,
label = waveform[ii].label,
linestyle = waveform[ii].linestyle)
scopePowerSubplot.legend().draggable(state=True, use_blit=True)
def scopeError(figure, s1, s2, grid):
......
......@@ -50,18 +50,30 @@ class Simulator(Simcore):
""" Redraws the figure
"""
# create waveforms
HDLWave = Waveform(value = self.yhdl,
label = 'HDL',
color = '#ff0000')
floatWave = Waveform(value = self.yfloat,
label = 'float',
color = '#0000ff')
simulatorWaves = [floatWave, HDLWave]
selectedPlot = str(self.comboSimulatorScope.currentText())
grid = self.cbGridSimulator.isChecked()
if selectedPlot == 'Time Plot':
scopeDual(self.figSimulator, self.yfloat, self.yhdl, grid)
scopeTime(self.figSimulator, simulatorWaves, grid)
elif selectedPlot == 'Error Plot':
scopeError(self.figSimulator, self.yfloat, self.yhdl, grid)
elif selectedPlot == 'Power Spectrum':
scopePower(self.figSimulator, self.yfloat, self.yhdl, grid)
scopePower(self.figSimulator, simulatorWaves, grid)
else:
scopeDual(self.figSimulator, self.yfloat, self.yhdl, grid)
scopeDual(self.figSimulator, simulatorWaves, grid)
# Change pushbutton state
self.pbUpdateFilter.setDisabled(True)
......@@ -118,7 +130,7 @@ class Simulator(Simcore):
# configuration tool in the navigation toolbar wouldn't
# work.
#
self.axesSimulator = self.figSimulator.add_subplot(111)
#self.axesSimulator = self.figSimulator.add_subplot(111)
# Bind the 'pick' event for clicking on one of the bars
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment