examples/fir: plot input and output signals

This commit is contained in:
Sebastien Bourdeauducq 2012-06-07 23:20:59 +02:00
parent 1c0f636c8d
commit b00e8fa826
1 changed files with 18 additions and 10 deletions

View File

@ -3,6 +3,7 @@
from math import cos, pi from math import cos, pi
from scipy import signal from scipy import signal
import matplotlib.pyplot as plt
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.fhdl import verilog from migen.fhdl import verilog
@ -58,15 +59,22 @@ def main():
# Compute filter coefficients with SciPy. # Compute filter coefficients with SciPy.
coef = signal.remez(80, [0, 0.1, 0.1, 0.5], [1, 0]) coef = signal.remez(80, [0, 0.1, 0.1, 0.5], [1, 0])
fir = FIR(coef) fir = FIR(coef)
tb = TB(fir, 0.3)
# Combine the FIR filter with its test bench. # Simulate for different frequencies and concatenate
fragment = autofragment.from_local() # the results.
sim = Simulator(fragment, Runner()) in_signals = []
sim.run(200) out_signals = []
# Print data from the input and output waveforms. for frequency in [0.05, 0.07, 0.1, 0.15, 0.2]:
# When matplotlib works easily with Python 3, we could tb = TB(fir, frequency)
# display them graphically here. fragment = autofragment.from_local()
print(tb.inputs) sim = Simulator(fragment, Runner())
print(tb.outputs) sim.run(100)
in_signals += tb.inputs
out_signals += tb.outputs
# Plot data from the input and output waveforms.
plt.plot(in_signals)
plt.plot(out_signals)
plt.show()
main() main()