0
$\begingroup$

I am trying to actuate a simple DC motor based on a wav file. At the moment I am using the "cat vs dogs sounds" from Kaggle.

One of the wav files in this DB looks like this:

enter image description here

These audio files are just a few seconds. The sample rate is 16KHz.

My first idea was to just actuate the motor based on the amplitude, but at 16KHz this doesn't make any sense. Also, the signal goes constantly from + to - (this is sort of ok because the motor can move in both directions), but from a human POV, what the motor does doesnt make any sense, because the movements are too rapid. I then tried to "decimate" the signal into a few points per second, but the signals seem to be badly destroyed.

DC motors are actuated using an Adafruit board, using Arduino, and then I have a Python script that interfaces with the Arduino through serial. I have this working fine, and I can make for example a loop from python that increases the speed every few seconds. My idea was to go forward or backwards based on the amplitude of the signal (if it is negative or positive), I am no expert on audio, so this might make no sense. I won't react to other sounds, only to the input wav files.

I don't really know what is the best way of transforming an audio signal of 16KHz into something that can be use to actuate a motor. At the moment I am using a DC motor, but the idea in the near future is to use leds instead, and change their intensity based on the audio signals

$\endgroup$
6
  • $\begingroup$ Are you using this for animatronics? Like when a dog barks in the wave file, the animatron should bark timed to the wave file? $\endgroup$ Jul 13, 2019 at 12:01
  • $\begingroup$ Short of yeah. Not exactly to "bark back" but "do something back". ideally I want to change the level of some LEDs, but at the moment I am happy just actuating motors. $\endgroup$
    – Dr Sokoban
    Jul 13, 2019 at 13:04
  • $\begingroup$ changing LEDs via analogwrite() or if you're using neopixels or something via a library is much easier than controlling a motor...to change the brightness/colour of LED's is trivial at 16khz...but impossible with a motor. a possible solution would be to resample your sound at the hz you're looking for...take the positive or negative half of your signal (either using a quadratic or just cutting off anything < 0 and then finding your peak via some logic and use that as your source. It'd be helpful if we had a link to one of your samples and some code...via pastebin or something. $\endgroup$ Jul 13, 2019 at 13:31
  • $\begingroup$ @morbo thanks for your answers. My samples are from the kaggle vs dogs kaggle sound DB: kaggle.com/mmoreaux/audio-cats-and-dogs and then I am reading them following this: kaggle.com/connerbrown/audio-cats-and-dogs-visualization and then what I want is to use the list read, which contains just numbers, to actuate the motor. I am not sure how I can resample the audio at a lower HZ $\endgroup$
    – Dr Sokoban
    Jul 13, 2019 at 14:01
  • 1
    $\begingroup$ i read your post several times and it appears that you have not said what you are trying to do .... actuate a motor is almost meaningless ... please rewrite your post to something like i have a signal ABC. i would like the motor to do XYZ in response to DEF in the signal $\endgroup$
    – jsotola
    Jul 13, 2019 at 20:01

2 Answers 2

1
$\begingroup$

You want to feed a lot of data to a slow consumer. Of course, you need to adapt somehow the two ends. I see the following options.

  1. You decide a sample frequency to feed data to the motor, suitable to the motor. The .wav file plays normally, when the time comes, you feed to the motor whatever sample happens to be current. Almost 100% that you will violate the Nyquist law, and whatever gets to the motor is "random" data.

  2. You apply low-pass filter to the .wav file, with a cut frequency adjusted according to the Nyquist law to the sampling frequency for feeding the motor. The data fed to the motor will be highly simplified, but somehow still related to the original stream.

  3. You play the .wav file at a speed which the motor can handle. I mean, you deliver all samples, but at (e.g.) 50Hz instead of 16kHz.

$\endgroup$
1
  • $\begingroup$ All of these answers are forms of low-pass filtering. Some are better than others, as you have rightly described $\endgroup$
    – SteveO
    Aug 8, 2020 at 23:04
0
$\begingroup$

You need to low-pass filter the input data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.