0
\$\begingroup\$

I've recently written a Matlab script to develop/simulate PWM output for RGB lights based on sampled audio input. I made this script with plans to actually construct a device that can run the algorithm and thus control RGB lights.

A brief explanation of the script (I'll post it below as well) is as follows.

  1. Filter the incoming signal into 3 bands of low, mid, and high range frequencies.

  2. Creates frames of 0.05 seconds in length (I think) to hold RGB values for the duration based upon the 3 filtered signals. Low = Blue, Mid = Green, High = Red.

  3. Use a peak ("bump") detector of sorts on the original sampled signal to look for volume increases in the song. The areas of high volume are recorded.

  4. Add Bumps to frames. To be honest, I'm not sure I like the way I implemented this and may change it in the future although I'm still trying to figure out a better way. I intend the "bumps" to change the color FROM the background color (created from the 3 filtered ranges) and then have the "bump" color fade to the background color until the next "bump" occurs.

  5. Draws a bunch of squares and displays an image to (hopefully correctly) simulate the colors and duration the lights will produce. Each column of color should represent an "interval" length (I have it to 0.05 seconds) of color. With this I should be able to visualize the expected output of the LED?

That's a quick overview of the script I want to implement in hardware. I'm honestly not sure it'll work but I have no way of knowing at the moment.

I have very little experience with actually working with hardware and am lost and have a few questions. I plan to get the analog signal from devices such as a phone audio jack.

In the Matlab script I've decided to sample at CD quality 44.1 kHz, but I'm not sure how to achieve this in hardware. Some have suggested a dedicated ADC which I agree may be a good idea, but I'm not sure how to shop for one. I'm not sure if I would need to sample at 16 bits for my purpose? What are some ADCs that could work for this purpose?

If I have a dedicated ADC I will need a way to transfer the information to another device. What is a good method to do this? I will want to perform filtering on the sampled signal as well as some data analysis to determine the value of 3 PWM output pins at a given time.

On the topic of filtering, since I am starting with an analog signal would it be easier to filter it before sampling with an ADC or digitally? I'm leaning towards digitally but I have no idea how to implement digital filters on a microcontroller.

I am also concerned about the speed and memory size of the microcontroller required to process the data. Assuming I can figure out how to interface an ADC with a microcontroller for processing, I would need to digitally fitler the signal into 3 bands as well as preserve the unfiltered signal for analysis. I also need to be able to keep an average of the last few thousand samples at a time (is an averaging filter a good way to do this? or a simple total_value/samples_taken a better implementation?) In my current design, I plan to update the PWM values for the LEDs every 0.05 seconds. What sort of microcontrollers would be able to accomplish these tasks as well as interface with an ADC?

Overall I'm looking for hardware that can perform the above operations, and I'm not sure what will work or where to start looking? Thanks in advance for any help.

MATLAB Script (pastebin link)

\$\endgroup\$
  • \$\begingroup\$ On EE stack exchange "Hardware" means electrical components, IC's a CPLD or FPGA. You mention a MCU so you want this implemented in software. \$\endgroup\$ – Oldfart May 12 '18 at 5:38
  • \$\begingroup\$ If you are more comfortable with MATLAB perhaps you can start with their Arduino support. \$\endgroup\$ – loudnoises May 12 '18 at 11:39
  • \$\begingroup\$ You can get microcontrollers with built-in ADCs, and multiple PWM outputs. If you buy a ready-made board with such a microcontroller, then the whole thing becomes a software problem. The difficult task is then simplifying your existing simulation software to the point that you can actually run it on the microcontroller. Learn to cut corners in the software algorithms - it's only flashing lights you want. If nothing else, drop the sample rate so you have less data to work through. \$\endgroup\$ – Simon B May 12 '18 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.