How to use scipy in micropython

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
mhwang1973
Posts: 9
Joined: Tue Jul 11, 2017 9:35 am

How to use scipy in micropython

Post by mhwang1973 » Tue Jul 11, 2017 9:41 am

as title. I am a newer of micropython, and I want to use scipy and numpy in pyboard. what can I do then?
thanks in advance.

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: How to use scipy in micropython

Post by torwag » Tue Jul 11, 2017 7:26 pm

Hi and welcome,
there is not much you can do as their is and will never be a port of numpy and scipy to Micropython. These are very huge libraries, which will never fit on a microcontroller, both in terms of memory and in terms of complexity.
The thing you can do, try to isolate what you want to do and see if this would be feasible to run on a microcontroller (e. g. does it use other libraries written in other languages like Fortran, does it use large amounts of memory?, will it perform reasonable fast enough on a 32 bit machine at around 80 MHz, etc.). If yes, use the numpy and scipy source code to understand the particular implementation, strip it down to the bare minimum and give it a test.

mhwang1973
Posts: 9
Joined: Tue Jul 11, 2017 9:35 am

Re: How to use scipy in micropython

Post by mhwang1973 » Wed Jul 12, 2017 8:37 am

Thanks for your reply. Now I have to code my own array/fft/fir and so on. They are the keys of my job.
Thanks again.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: How to use scipy in micropython

Post by pfalcon » Wed Jul 12, 2017 10:39 am

You don't really "have" to, MicroPython is a mature project within its niche, and other people coded at least some of those things already - search the forum. Of course, what they did might not satisfy you, and you indeed may need to implement it in right way for yourself.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How to use scipy in micropython

Post by pythoncoder » Thu Jul 13, 2017 7:06 am

mhwang1973 wrote:Thanks for your reply. Now I have to code my own array/fft/fir and so on. They are the keys of my job.
Thanks again.
MicropPython supports the array module. You might also like to look at my attempts at FFT https://github.com/peterhinch/micropython-fourier.git and FIR https://github.com/peterhinch/micropython-filters.git. They don't aim to compete with the big libraries - their aim is fast execution on the Pyboard.
Peter Hinch
Index to my micropython libraries.

User avatar
Wei Lin
Posts: 21
Joined: Sat Jan 21, 2017 1:07 pm

Re: How to use scipy in micropython

Post by Wei Lin » Sat Oct 07, 2017 2:35 am

FFT is so important for signal processing and many other usages, also ESP32 has ADC and DAC.

It will be very nice if FFT is built into MicroPython.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

ESP32 ADC's and DFT

Post by pythoncoder » Sat Oct 07, 2017 10:54 am

From initial tests the ESP32 ADC and DAC aren't as accurate as those on the Pyboard.

As a general point re FFT, a DFT routine in Python will be portable and examples abound on the web. To sate the obvious it may not be fast enough for realtime DSP even if you use the high performance code emitters. The solution is to use assembler. My Arm Thumb attempt is fairly fast, but could undoubtedly be optimised further, perhaps by up to a factor of two.

I doubt that the MicroPython maintainers will write an optimised DFT in assembler for each target arch. It's up to us, the users, to do this; it's more grunt-work than rocket science ;) Likewise FIR and IIR filters benefit hugely from asm.

I have no particular ambition to use an ESP32 for DSP.
Peter Hinch
Index to my micropython libraries.

Post Reply