Go Down

Topic: Mix several sinewaves? (Read 4635 times) previous topic - next topic

aidvllasaliu

Hello guys!

I have seen on the internet that people turn their Arduinos into sinewave generators fairly easy.

How could I somehow mix several sinewaves with different frequencies that are going to be played back by the Arduino?

Also, how can I generate frequencies at the 20kHz range and above?
Faster clockspeeds?
Faster PWM's?
External chip?

Throw any suggestions in here, I am interested in anything!

Grumpy_Mike

We need way more information.
PWM is a poor way of generating a sin wave, much better is to use an A/D converter.
If you must use PWM then you should have the PWM frequency set to a value at least 256 times the output sample rate of the waveform.
To mix the waves you can either add up the samples before outputting them or generate the waves on separate pins and just connect the different pins up through resistors to a summing point. For better results also include a series capacitor on each pin. 

AiRgeek

#2
Mar 31, 2014, 02:35 pm Last Edit: Mar 31, 2014, 02:37 pm by AiRgeek Reason: 1
If you are looking for a high resolution i.e. low distortion sin wave, you may want to consider using a direct digital synthesizer (DDS) controlled by the Arduino, then use op amp summer to mix the signal.

<a href="http://www.analog.com/library/analogdialogue/archives/38-08/dds.html">Direct Digital Synthesis</a>

CrossRoads

Quote
Also, how can I generate frequencies at the 20kHz range and above?

That hardly seems audio.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

polymorph

Mix or add? The two mean different things, or at least they can. To be fair, we call an audio board a "mixing console", but generally, "mixing" different frequencies can mean that you are putting them through a nonlinear device that will then output sum and difference frequencies.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

DVDdoug

Quote
Mix or add? The two mean different things, or at least they can. To be fair, we call an audio board a "mixing console"...
An analog mixer is built with a summing amplifier.   If you mix a vocal and a guitar, they are summed.   Digitally, we usually need to scale-down the samples before mixing because the sum may exceed the value we can hold with a fixed number of bits.

polymorph

I'm asking the OP to clarify in which sense he means mixing.

Top hit for "sine mixer":
en.wikipedia.org/wiki/Frequency_mixer

And as I said, an audio mixer is generally actually a summing amplifier.

Just asking the OP to clear this up.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

aidvllasaliu

Wow! Much replies! Such help! Great thanks!

Doge jokes aside: Thanks guys.


I'm asking the OP to clarify in which sense he means mixing.

Top hit for "sine mixer":
en.wikipedia.org/wiki/Frequency_mixer

And as I said, an audio mixer is generally actually a summing amplifier.

Just asking the OP to clear this up.


I don't quite know now when you're asking me.

I would like to mix two sine waves in the same way that one would mix two audio files.

Lets say one sine is at 500Hz, and the second sine is at 1000Hz, the output should be
both of them at the same time through the same DAC.

In my application, the sines might or might not be on at the same time, therefor I need to mix them together.

Imagine how a music mixing software works, you have two songs, you can play one song at a time, or both of them at
the same time.

that's more or less how I want to work with sinewaves.


Quote
Also, how can I generate frequencies at the 20kHz range and above?

That hardly seems audio.


Yes, it does not have to be audio in the human hearable range. As long as a FFT can capture it it is alright.


If you are looking for a high resolution i.e. low distortion sin wave, you may want to consider using a direct digital synthesizer (DDS) controlled by the Arduino, then use op amp summer to mix the signal.

<a href="http://www.analog.com/library/analogdialogue/archives/38-08/dds.html">Direct Digital Synthesis</a>



That one looks nice. I will read more about it.

polymorph

We should speak more clearly than the general public does. So with that in mind, what you want to do is -add- several sine waves together, not mix them.

As DVDdoug points out, you'll need to make sure the result does not end up with more bits than the output device can handle.

Are you trying to make an arbitrary waveform generator?

What is the maximum frequency you wish to have come from this?

As far as summing several sine waves, it is as simple as adding. Keep in mind that if you add two 8 bit sine waves, the result requires 9 bits to hold it. Add four 16 bit sine waves, you'll need 20 bits.

I'd add them, then decimate after summing them.

The Teensy 3.1 has a digital to analog converter (ADC) which would make this much easier to get out of the microcontroller. I don't know what its maximum frequency is, but it is meant to at least do audio. It also has a -lot- more program space to store a table of values for a sine wave, which would be much less load on the CPU than doing floating point trig while running. You only need to store 1/4 of a sine wave. Run it backwards for the 2nd 90 degrees, then inverted for the 3rd 90 degrees, then backwards and inverted for the 4th 90 degrees.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

retrolefty

Quote

We should speak more clearly than the general public does. So with that in mind, what you want to do is -add- several sine waves together, not mix them.


I'm sure in professional recording engineering world that 'mixing' is the term they use to add (sum) audio signals into one output signal.
Just different jargon for different disciplines.

polymorph

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

bosleymusic

Mix or add? The two mean different things, or at least they can. To be fair, we call an audio board a "mixing console", but generally, "mixing" different frequencies can mean that you are putting them through a nonlinear device that will then output sum and difference frequencies.

A summing bus is what's used in a mixer, it adds the signals together - mixing.  Multiplication in the time domain will give you the sum and difference frequencies - sideband/ring/balanced modulation depending on the implementation. To generate sine waves of that high of a frequency you'll need something with a much faster DAC than any of the arduino's I think can handle - especially if your DAC clock and the peak-to-peak values of your sine wave aren't in alignment.

You should investigate table lookup, or wavetable synthesis along with how to change clocking speeds and getting the most from the DAC on your particular arduino - you'll also most likely need to smooth your signals on output if you're generating frequencies that high as your output will probably be more like a square than a sine.

Go Up