v923z / micropython-ulab

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

Add keyword arguments to spectrogram #657

Open v923z opened 5 months ago

v923z commented 5 months ago

Details and rationale are outlined in https://github.com/v923z/micropython-ulab/blob/spectrum/docs/ulab-utils.ipynb, but the gist is that spectrogram now allows for the re-use of allocated memory (through the out, and scratchpad keyword arguments), as well as direct calculation of the logarithm (through the log keyword argument).

from ulab import numpy as np
from ulab import utils as utils

n = 1024
t = np.linspace(0, 2 * np.pi, num=1024)

scratchpad = np.zeros(2 * n) # re-usable RAM for the calculation of the FFT

for _ in range(10):
    signal = np.sin(t)  # this simulates a measurement of some signal
    utils.spectrogram(signal, out=signal, scratchpad=scratchpad, log=True)

@jepler, @dhalbert this might be relevant for circuitpython users.