Deploy bandpass filters using the Wolfram Language Microcontroller Kit
Wolfram Research, Inc.
In this project I will analyze the responses of a bandpass Butterworth and Chebyshev1 filter deployed to an Arduino Nano from the Wolfram Language.
As these are analog filters, they need to be discretized before deployment. It is interesting to see in real-time how the frequency response of deployed filter closely matches that of the analog version.
The frequency responses create a mental imagery of what the real-time responses of the filters would look like and how they would differ from each other. But I wanted to make it concrete. So I created a visualization juxtaposing the frequency responses of the analog filters and the real-time responses of discretized filters, to see both in real-time as I change the parameters of the input signals.
In the first part, the filters are computed, analyzed, and deployed. In the second part, I acquire and analyze the filtered data to visualize the responses and evaluate the performance of the filters.
I start off by creating a function that will compute a filter with passband frequencies of 2 Hz and 5 Hz, stopband frequencies of 1 Hz and 10 Hz, and an attenuation of -30 dB at the stopband frequencies.
(The port name /dev/cu.usbserial-A106PX6Q will not work for you. If you are following along you will have to change it to the correct value. You can figure it out using DeviceManager on Windows, or by searching for file names of the form /dev/cu.usb* and /dev/ttyUSB* on Mac and Linux systems. )
At this point, I can connect any other serial device to send and receive the data. I will use device framework in Mathematica to do that, as its notebook interface provides a great way to visualize the data in realtime.
Acquire and display the data
To set up the data transfer, I begin by identifying the start, delimiter, and end bytes.
Then I create a scheduled task that, reads the filtered output signals and sends the input signal over to the Arduino, and runs at exactly the same sampling period as the discretized filters.
I also create a second and less frequent scheduled task that parses the data and discards the old values.
Now I am ready to actually send and receive the data, and I open a connection to the Arduino.
I then generate the input signals and submit the scheduled tasks to the kernel.
At this point, the data is going back and forth between my Mac and the Arduino. To visualize the data and control the input signals I create a panel. From the panel, I control the frequency and magnitude of the input signals. I plot the input and filtered signals, and also the frequency response of the filters. The frequency response plots have lines showing the expected magnitude and phase of the filtered signals, which I can verify on the signal plots.
Since the Arduino needs to be up and running to see the panel update dynamically, I am going to include some screenshots of the results.
Finally, before disconnecting the Arduino, I remove the tasks and close the connection to the device.