* Why is writing DSP algorithms in C slow? Can you e.g. come up with better libraries (existing or your own), utility functions, headers, macros to help development?
* Why is Javascript needed to prototype on PC? Surely PCs run software written in C all the time. I understand the advantage of a browser, but can you come up with an alternative way to feed data into browser, or visualize from C with something else than browser?
The slow part is updating of visualization code. With an HTML+JavaScript tab in a browser some changes can be made faster, and then I can try few smaller changes literally spending 3 seconds each by pressing F5 and looking into graphs/console. With the microcontroller tools there is a lag coming from building, flashing, looking for the output in serial monitor (e.g., responses to different commands). With a JavaScript it feels so much faster: I have notepad++ opened and a web browser tab + console on the second monitor. Make a change - F5 - ready.
It seems that development goes faster when the visualization and the algorithm both implemented using same language (JavaScript in this case). I tried STM32CubeMonitor multiple times, but the usability kind of worse than simply putting HTML buttons/canvases and using several JavaScript functions. Dynamic typing accelerates the development, but followed by a tedious conversion, very prone to bugs (overflows).
You are right about better libraries, maybe some custom solution to ease the visualization process, to exchange the data between browser and microcontroller using a more standardized way.
JavaScript is never going to be tiny, or fast on a microcontroller, but here is one that has been used for more than a decade at Samsung designed for largish ones: 64k RAM, >256k flash
https://github.com/jerryscript-project/jerryscript
I've seen this one. Interestingly, my search started from the opposite: I tried to find a C interpreter written in JavaScript, or something that allows to use C code directly from JavaScript functions.
I would prototype it on a desktop computer using test data in files. Make sure it's at least working correctly and doing what it's supposed to before even considering putting it on a microcontroller, because debugging it there will be significantly more difficult. Optimize it on the desktop, at least the things you mention. Then port it to a microcontroller. JS, however, is probably not fast enough, but once the basic functionality is correct as long as you don't wrap it into obscenely complicated, highly normalized functional code, just reimplementing it as C/C++, perhaps with select inline assembly, should be straightforward.
You are absolutely right. That's exactly what I am doing. Here is my workflow:
1. I create a simple firmware that streams sensor data to the serial port and saved to a computer file, very similar to audio recorder.
2. I load this file into my JavaScript template. I already have several templates from previous projects that allow to load and parse binary files. For example, some sensors provide 16-bit data, 32-bit data, signed/unsigned, etc. At this point I have one or several arrays filled with the recorded data
3. I start to create an algorithm. Again, have multiple snippets of code from previous projects that allow me to output 1D/2D data on HTML Canvas, scroll through it, display values under the cursor.
4. I test the algorithm on several recordings as shown in
this video. I have used recordings for up/down/left/right and rotational gestures.
After algorithm is ready and tested on several recordings, the tedious part begins. I start to transfer the code from JavaScript to C.
At this point I use web serial api to stream recorded data back to the microcontroller to emulate sensor output. Resulting variables are streamed back to the browser and visualized along with JavaScript algorithm graphs. For example, I compare FFT output, that I have the same magnitudes. Or I compare correlation coefficient graph. If something is wrong, graphs will be different.
I get a very good working algorithm fast, but then I struggle with the "transfer" part. This
video shows before/after and scrolling through the data recordings using web browser.
Update: I re-read my topic and here is the summary:
- I quickly develop great algorithms on my PC in JavaScript, but then I waste a lot of time porting them to C for the microcontroller
- Know about MicroPython and open-source JavaScript interpreters, but these great tools come at a cost in terms of memory and performance requirements
- Familiar with Matlab/Octave, but it still requires rewriting the algorithm in C
- Pretty experienced with STM32CubeMonitor (Node-RED based), but I find it somewhat clunky. It would feel more natural if I could access visualization tools directly from the C source code