Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fir.py bug #2

Open
fsincere opened this issue Jan 25, 2022 · 2 comments
Open

fir.py bug #2

fsincere opened this issue Jan 25, 2022 · 2 comments

Comments

@fsincere
Copy link

fsincere commented Jan 25, 2022

Hi Peter,
I try fir.py with MicroPython 1.17 on NUCLEO-L476RG board.
There is a problem only when the number of coefficients is a multiple of 4.
For exemple :
coeffs = array.array('i', (100, 100, 100, 100))
ncoeffs = len(coeffs)
data = array.array('i', [0]*(ncoeffs +3))
data[0] = ncoeffs
data[1] = 0
fir(data, coeffs, 1) # 100 OK
fir(data, coeffs, 0) # 100 OK
fir(data, coeffs, 0) # 100 OK
fir(data, coeffs, 0) # 134492960 bug

coeffs = array.array('i', (0, 100, 100, 100, 100)) works !

@peterhinch
Copy link
Owner

I can confirm this bug on a Pyboard. I will investigate.

@peterhinch
Copy link
Owner

Thanks for the report. I've pushed an update to fix this.

It was a classic array bounds error, performing one iteration too many and accessing a coefficient value from the location after the end of the array. This actually occurred regardless of the number of coefficients. A quirk of the array module caused the value in this location to be zero except when len(coeffs) % 4 == 0. This caused the bug only to be apparent under those conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants