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

pState: use pState from argument #80

Closed
wants to merge 1 commit into from

Conversation

charansai612
Copy link
Contributor

pState is set to zeros internally even when pState is a non zero array

pState is set to zeros internally even when pState is a non zero array
@christophe0606 christophe0606 added the review Under review label Jan 9, 2023
@christophe0606
Copy link
Contributor

@charansai612 It is normal for the init function to reset the state to 0. It is in fact their main function : setting the filter into a known state.

If you need to set the state to another value, you may do it after the init. But why would it be needed ? Goertzel algorithm using a biquad ?

Note also that it won't be portable : the state encoding may be different depending on the core you target (vectorized filter etc ...). So if you rely on what is in the state for your own code, it may break if you move the algorithm to another target.

The state should only be used by the filter.

@christophe0606 christophe0606 added wontfix This will not be worked on DONE Issue done but not yet closed and removed review Under review labels Jan 9, 2023
@christophe0606
Copy link
Contributor

I won't change the init functions. But if there are some needs for having a different state at start of the filter, feel free to open a github issue for an enhancement request and explain your use case and we will see what would be possible taking into account all of the constraints we have (like the different filter implementations).

@charansai612
Copy link
Contributor Author

I just implemented the python like sosfiltfilt using the arm_biquad_cascade function and found out the pState is set to zero, I generated pState from the scipy in order to avoid the boundary effect.

Ya updating the state after init should also work.
Thank you

@christophe0606
Copy link
Contributor

Thank you. I have created a github issue for a future enhancement:
#83

@Lukwrt
Copy link

Lukwrt commented May 20, 2024

@charansai612 I am also trying to replicate sosfiltfilt from Scipy (see sosfiltfilt code source). However I don't get how to convert valuesfrom sosfiltzi to pstate argument of arm_biquad_cascade_df1_init_f32.

Let's say my zi computed via Scipy are :
[[1 , 2]
[3 , 4]]

How do I convert it to proper pStates for the biquad function ?
I tried to assign to pState "like this" : pState = {1, 2, 3, 4} but the result is not the same as I get in Scipy.

Should I post this comment in #83 ? As my comment is very closely related to this possible enhancement.

@Lukwrt
Copy link

Lukwrt commented May 20, 2024

I'm sorry for my previous comment. I was using the biquad cascade direct form 1 from CMSIS-DSP to implement Scipy sosfiltfilt but it was a mistake as this scipy function uses a direct form 2 structure. So switching to the biquad cascade direct form 2 in CMSIS works perfectly. I also have to compute the initial condition via sosfiltzi in Scipy but it is not a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DONE Issue done but not yet closed wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants