Many/most microcontroller boards have analog-to-digital converters built into them, it is very convenient. E.g. it is the case for the Raspberry Pi Pico.
Output: another sequence of complex numbers such that:Intuitively, this means that we are braking up the complex signal into sinusoidal frequencies:and is the amplitude of each sine.
- : is kind of magic and ends up being a constant added to the signal because
- : sinusoidal that completes one cycle over the signal. The larger the , the larger the resolution of that sinusoidal. But it completes one cycle regardless.
- : sinusoidal that completes two cycles over the signal
- ...
- : sinusoidal that completes cycles over the signal
We use Zero-based numbering in our definitions because it just makes every formula simpler.
Motivation: similar to the Fourier transform:In particular, the discrete Fourier transform is used in signal processing after a analog-to-digital converter. Digital signal processing historically likely grew more and more over analog processing as digital processors got faster and faster as it gives more flexibility in algorithm design.
- compression: a sine would use N points in the time domain, but in the frequency domain just one, so we can throw the rest away. A sum of two sines, only two. So if your signal has periodicity, in general you can compress it with the transform
- noise removal: many systems add noise only at certain frequencies, which are hopefully different from the main frequencies of the actual signal. By doing the transform, we can remove those frequencies to attain a better signal-to-noise
Sample software implementations:
- numpy.fft, notably see the example: numpy/fft.py
An upstream repo at: github.com/raspberrypi/pico-micropython-examples
Our examples at: rpi-pico-w/upython.
The examples can be run as described at Program Raspberry Pi Pico W with MicroPython.
- rpi-pico-w/upython/blink.py: blink on-board LED. Note that they broke the LED hello world compatibility from non-W to W for God's sake!!!
- rpi-pico-w/upython/led_on.py: turn on-board LED on and leave it on forever
- rpi-pico-w/upython/uart.py: has automatic UART via USB. Any
print()
command ends up on the Raspberry Pi Pico W UART! Is is just like with Micro Bit, must be a standard Micro Python thing. The onboard LED is blinked as a heartbeat. - rpi-pico-w/upython/blink_gpio.py: toggle GPIO pin 0 on and off twice a second. Also toggle the on-board LED and print to UART for correlation. You can see this in action e.g. by linking an LED between pin 0 and one of the GND pins of the Pi, and the LED will blink.
- rpi-pico-w/upython/pwm.py: pulse width modulation. Using the same circuit as the rpi-pico-w/upython/blink_gpio.py example, you will now see the external LED go from dark to bright continuously and then back
- rpi-pico-w/upython/adc.py: analog-to-digital converter. The program prints to the UART the value of the ADC on GPIO 26 once every 0.2 seconds. The onboard LED is blinked as a heartbeat. The hello world is with a potentiometer: extremes on GND and VCC pins of the Pi, and middle output on pin 26, then as you turn the knob, the uart value goes from about 0 to about 64k.