v923z / micropython-ulab

a numpy-like fast vector module for micropython, circuitpython, and their derivatives
https://micropython-ulab.readthedocs.io/en/latest
MIT License
416 stars 114 forks source link

[FEATURE REQUEST] add Hilbert transform #436

Open labodezao opened 3 years ago

labodezao commented 3 years ago

Hi, I wonder if it's possible to implement the hilbert transform with micropython ulab. Best regards

v923z commented 3 years ago

I assume, you want the implementation of https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.hilbert.html. However, before we add that, I wanted to ask, whether you could already calculate the Hilbert transform via the Fourier transform by applying the relation: Relationship with the Fourier transform.

labodezao commented 2 years ago

Hi, this is the right feature. It's certainly possible to code this manually, yes, but some of my tries where hazardous :)

v923z commented 2 years ago

OK, but the question is, whether this has to be implemented, if the same functionality can be gotten with the already available tools. In order to keep the flash size small, I would rather implement things with some python wrapper. https://github.com/v923z/micropython-ulab/tree/master/snippets

labodezao commented 2 years ago

Hmm yes i did not think about it :)

v923z commented 2 years ago

@labodezao I am not sure, where this issue stands now. Do you want to implement this functionality as a snippet, or should we close it?

labodezao commented 2 years ago

This could be a good idea, but I don't have the knoloedge to modify the code :)

v923z commented 2 years ago

This could be a good idea, but I don't have the knowledge to modify the code :)

But if it is supposed to be a snippet, then you would write the code in python, so you would not have to change anything in the code base. That's the beauty of it.

labodezao commented 2 years ago

How can I do that ?


http://labodezao.fr/

Ewen d'Aviau 9 rue fernand de Magellan 44600 Saint-Nazaire 06-02-37-53-22

Le sam. 29 janv. 2022 à 18:14, Zoltán Vörös @.***> a écrit :

This could be a good idea, but I don't have the knowledge to modify the code :)

But if it is supposed to be a snippet, then you would write the code in python, so you would not have to change anything in the code base. That's the beauty of it.

— Reply to this email directly, view it on GitHub https://github.com/v923z/micropython-ulab/issues/436#issuecomment-1024950257, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALPYWOME5KNOBZAFWWCM2EDUYQN73ANCNFSM5DCRD4TA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

v923z commented 2 years ago

You have access to the Fourier transform, and then you use what is written in https://en.wikipedia.org/wiki/Hilbert_transform#Relationship_with_the_Fourier_transform. You can calculate the phase of your signal by calling np.atan2, and then shift the phase by +/-90 degrees. This all can be done in python.

EDIT: if this is performance-critical, we could move the calculations to C, but first I would like to see a working implementation in python.