Created
March 31, 2020 18:26
-
-
Save controlpaths/aa2f8f4d14f1df9caf1cdd4cffabac11 to your computer and use it in GitHub Desktop.
Python code for 8 order FIR configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynq import Overlay | |
| import numpy as np | |
| from scipy import signal | |
| import matplotlib.pyplot as plt | |
| from pynq import MMIO | |
| # Configure the overlay | |
| overlay = Overlay("ultra96_bd_fir.bit") | |
| # Define the IP addresses and definition | |
| IP_BASE_ADDRESS = 0x00B0000000 | |
| IP_HIGH_ADDRESS = 0x00B0000FFF | |
| ADDRESS_RANGE = IP_HIGH_ADDRESS-IP_BASE_ADDRESS+1 | |
| fir8 = MMIO(IP_BASE_ADDRESS, ADDRESS_RANGE) | |
| # FIR filter design | |
| nTaps = 8; # FIR filter 8th order | |
| fs = 10e3/2 # This value is corresponding with the Nyquist frequency | |
| fc = 3000 | |
| wc = fc/fs | |
| taps = signal.firwin(nTaps, wc) | |
| w,h = signal.freqz(taps) | |
| plt.plot(w, 20 * np.log10(abs(h)), 'b') | |
| # Filter quantification | |
| nBits = 32 | |
| tapsQ = [] | |
| for i in taps: | |
| tapsQ.append(np.int(i*2**(nBits-1))) | |
| # Write filter coefficients on IP | |
| coeffIndex = 0 | |
| for j in tapsQ: | |
| fir8.write(coeffIndex,j) | |
| coeffIndex = coeffIndex+4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment