• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Turn a square wave into a sine wave?

Status
Not open for further replies.

ClydeCrashKop

Well-Known Member
Most Helpful Member
Hi Guys / Gals

I am trying to make a Biofeedback type of thing with a Arduino Uno and a pulse monitor. Hopefully my girlfriend can use it to lower her heartbeat & calm herself so she can sleep.

The problem is that the Arduino tone function puts out a square wave that sounds abrasive on a small speaker. I would like a soothing hummmm at frequencies from A4, 440 Hz down to B0, 31 Hz.

I don't know much analog or music.
How do I turn a 50% square wave into a sine wave? Are attack and decay asking too much?
 

schmitt trigger

Well-Known Member
Since the square wave is essentially a sinewave with odd-order harmonics, the best is to have a higher-order, low-pass filter to filter anything above the fundamental.

Since you want different frequencies, you have to have a tuneable filter.
Fortunately, it is a snap with switched capacitor filers, like the MF10, where the clock frequency is a multiple (50X or 100X) of the cutoff frequency.
EDIT:::::::
I actually found a much better device, from Linear Tech.

http://www.linear.com/product/LTC1064-2
 
Last edited:

MikeMl

Well-Known Member
Most Helpful Member
Slightly more than a ten-to-one frequency range... I would try an Arduino-controlled sine wave oscillator. You might be able to get some ideas here or here.
 

JimB

Super Moderator
Most Helpful Member
While it may seem to be a bit of overkill, can I suggest one of the AD9850 DDS modules which are cheaply available.
Look here:
http://www.ebay.co.uk/sch/i.html?_n...odules&geo_id=32251&poi=&crdt=0&ul_noapp=true

Just send a 32bit serial tuning word to the module and you will get out the exact frequency sinewave you require.

These things are usually associated with RF applications, but they work nicely all the way down to DC.

JimB
 

canadaelk

Active Member
TI AP note AN-263, section 9: Sine Approximation, Breakpoint Shaper, is frequency independent and you can add diode networks to reduce distortion. E
 

MrAl

Well-Known Member
Most Helpful Member
Hi,

There is actually a PWM method for generating sines too, where you bang the output with pulses of different widths to force the output to be the piecewise time average of a sine wave of whatever frequency you need. Since you only need up to about 440Hz this should be possible. The output then is much easier to filter and looks more like a sine wave.

When generating a square wave, the output is turned on for about 50 percent of the time, and off for 50 percent of the time, at the frequency needed. When generating a sine wave, a three pulse method would be to turn the output on for a short time period, say 5 percent, then turn off for say 5 percent, then on for say 30 percent of the time, then off for say 5 percent, then back on for 5 percent, then off for 5 percent, etc. That's a guess of the required pulse widths but that's the basic method. The actual pulse widths are calculated based on the actual average the sine is supposed to be at that point.
At zero degrees there is no amplitude, so there is no pulse, at 90 degrees there is max amplitude, so there the pulse width is max too. If the max pulse width is 20 degrees, then the pulse between zero and 90 degrees occurs at 45 degrees, and the average amplitude has to be 0.707 so the pulse width there has to be 14.1 degrees, and the pulse width at 90+45 degrees is also 14.1 degrees. That's using only three pulses per half cycle, just a quick example.
There are other ways of doing it though too, such as selecting the pulse widths based on completely eliminating the 3rd harmonic which is the worst one, which then makes it easier to filter.

Another simple way is to use a weighted resistor divider, with four top resistors and one bottom resistor that forms a variable voltage divider. The four upper resistors are chosen to provide one of 16 different amplitudes when connected to 4 output ports. The output is much easier to filter than a square wave. The i/o ports are driven with signals that are spaced in time according to what is needed in the sine wave at that time. Since the resistor values could be something like 8k, 4k, 2k, and 1k, connected say to pins 8,4,2, and 1 (for example) to get the level at 90 degrees all output ports would be set to 1, and at 45 degrees only ports 8 ,2, and 1 are set to 1 with 4 set to zero. This idea gives a much closer approximation to the sine wave without having to buy much, just the resistors, and a single capacitor filter.

The AD device Jim mentioned is easy to use too, just send it the digital code that corresponds to the frequency you need, and there is already a library for it so you dont have to do much to get it to work.

You can see there are a lot of ways of doing this. You have to figure out what is the way you prefer based on what you already have and what you are willing to buy, and how much trouble you dont mind going through to get it to work.
 

ClydeCrashKop

Well-Known Member
Most Helpful Member
Thanks a lot for all the info. I have a few op-amps and almost enough parts to make a lot of those circuits.

I remembered this from a movie years ago. A light would fade on and off at about 1/3 of the pulse rate and a tone would fade on and off at the same time. Lower frequency for lower heart rate. The character would consciously try to lower their heart rate.

Arduino stuff is too easy. There are numerous projects using this DDS Signal Generator Module AD9850 0-40Mhz Sine Square Wave. So I bought this one http://www.ebay.com/itm/DDS-Signal-...411739?hash=item35e3c20bdb:g:RKoAAMXQhpdR1RtA

To fake attack and decay, I may set the frequency and then fade the volume on and off along with the light.

I may still try some of those circuits while waiting for that board. I started with an R-C filter and almost got acceptable sound in the middle frequencies but low frequencies were almost square waves and high frequencies were saw tooth.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top