# Square wave to Sine wave (variable frequency)

Discussion in 'General Electronics Chat' started by teliocide, May 2, 2015.

1. ### teliocide Thread Starter Member

Sep 26, 2013
55
0
Greetings,

I need to convert a varying frequency square wave signal to the corresponding sine wave frequency.
Firstly, the square wave is not symmetrical in that the Off time is about 7 times the On time.
The voltage of the square wave is relatively constant 13.6 volts ( I am using a battery charger as a power supply). The frequency range is from 0 to 150 Hertz, quite low.
The sine wave does not have to be perfect.

I dont know where to start

2. ### crutschow Expert

Mar 14, 2008
23,092
6,850
Don't offhand see any easy way to do that.

3. ### #12 Expert

Nov 30, 2010
18,076
9,691
This is basically impossible, especially when you include zero cycles per second, or 1/1000th of a cycle per second.
Maybe if you tell us what you need instead of what you want, somebody might have an idea.

Sinus23 likes this.
4. ### teliocide Thread Starter Member

Sep 26, 2013
55
0
It doesnt matter if the system doesnt kick in until a few cycles per second.
I was thinking indirect conversion maybe required. IE sample over a few milli seconds and use the calculated value to drive a sine oscillator at the derived frequency.
Maybe something like an arduino could be used.???????

5. ### MikeML AAC Fanatic!

Oct 2, 2009
5,444
1,075
A PLL to steer a much higher frequency VCO . Use the VCO to advance a counter (could be the same counter as used in the PLL frequency divider) to address a sine look-up table ROM, which drives a DtoA. This can be done with hardware or in code inside a microcontroller.

DickCappels likes this.
6. ### AnalogKid AAC Fanatic!

Aug 1, 2013
8,079
2,285
Not sure you need the PLL. The uC can measure the period of one cycle and use a second lookup table (basically 1/t) to set the frequency of the internal clock/counter driving the sine DAC. 1 Hz resolution means 150 values in the table. OK, rereading this it does sound like a form of a digital PLL.

ak

7. ### dl324 AAC Fanatic!

Mar 30, 2015
8,724
2,107
I'd try a low pass filter and see what you get. It's not going to look anything like a sine wave because you don't have an appropriate input signal. Since frequency is varying, trying to do it with a fixed frequency filter will give less than ideal results. You need to pick the 3db frequency where you think it'll give you the best results.

8. ### Nykolas Active Member

Aug 27, 2013
114
37
The OP (or TS) does not indicate power requirements. In early electronic music this was done with an op-amp and a bunch of resistors and diodes in the feedback loop. In high power applications a ferroresonant transformer could be used. E

9. ### wayneh Expert

Sep 9, 2010
16,102
6,219
If you don't need great precision in the frequency, you could do a frequency-to-voltage on the square wave signal, and use that voltage to drive a voltage-to-frequency sine wave oscillator. You could even calibrate it if you have an oscilloscope.

10. ### teliocide Thread Starter Member

Sep 26, 2013
55
0
Thanks Wayneh,
Sounds very feasible ....... any suggested circuits?

11. ### Brownout Well-Known Member

Jan 10, 2012
2,364
1,000
Rec wave 2 sawtoots. DC filter. Full wave rectifier. Triangle 2 sinewave. Will write more when I have a better ketboard. Using text now.

12. ### ScottWang Moderator

Aug 23, 2012
6,759
1,047
The simple circuit as below that you can change the values and test it first, and you may need to using switches to switching them in different frequency, if the voltage amplitude is not enough then you can add a op amp to amplifying the signal.

13. ### WBahn Moderator

Mar 31, 2012
24,555
7,691
The problem that I see in a couple of the recommended approaches is that they rely on being able to filter out the higher harmonics. But with a frequency range of 0 Hz to 150 Hz (even if we start at a few Hz instead of zero) is that the very low end of the frequency range is going to contain a lot of harmonic content that will get through the filters.

While there are several viable approaches, including several that have been mentioned, I tend to favor the one that was offered in which the period of the pulse train is measured and then that is used to control the DDS (direct digital synthesis) of a sinewave generator by controlling how far a loop steps through a lookup table in memory.

14. ### dl324 AAC Fanatic!

Mar 30, 2015
8,724
2,107
The OP said the "square" wave had a 1/8 duty cycle and that the "sine" wave didn't need to be perfect. OP didn't mention desired complexity for a solution, so a low pass filter seems reasonable as a first order approximation of a sine wave from an input signal that can't generate anything resembling a sine wave.

15. ### WBahn Moderator

Mar 31, 2012
24,555
7,691
How reasonable is a "first order approximation" of a rectangular wave that contains dozens of harmonics? Seems like it would look an awful lot like a rectangular wave and nothing remotely like a sinewave, imperfect or otherwise. Perhaps I am not taking into account the influence of the low duty cycle strongly enough. The proof would be in finding the Fourier coefficients for a 2Hz, 1/8 duty cycle waveform and seeing what the components that are below 150 Hz would produce. I just don't feel like doing it -- but it's something the TS might consider doing.

16. ### wayneh Expert

Sep 9, 2010
16,102
6,219
The frequency to voltage part can be accomplished with a 555 circuit. I built one that was shown in the old Forrest Mimms 555 booklet and it worked well in the audible range.

I'm not sure about the voltage-controlled-oscillator VCO. There are many but only a subset will give a sine wave. Hopefully someone here has a good VCO offering.

17. ### Alec_t Expert

Sep 17, 2013
10,255
2,505
You can get a fair synthesised sinewave by using weighting resistors on the outputs of an 8-bit shift register with feedback. The register needs to be clocked at 16 times the desired output frequency (but that would then leave the problem of creating a 16 x frequency multiplier clocked by the rectangular wave).

18. ### dl324 AAC Fanatic!

Mar 30, 2015
8,724
2,107
The problem is that the OP didn't weigh in on the low pass filter approach. Perhaps s/he doesn't understand the complexity of the problem or of the proposed solutions.
Same here. I don't feel like putting more work into finding a solution than the person asking for one. The requirement of converting a variable frequency rectangular wave to sine could be complex, or not, the OP wasn't very active in helping to converge on a solution.

19. ### AnalogKid AAC Fanatic!

Aug 1, 2013
8,079
2,285
One way to help the frequency range / filter cutoff freq tracking problem is with a PLL. Lock to the input signal, multiply up to a high freq, use that to clock a Linear Tech switched-capacitor lowpass filter to filter the input squarewave to a sine. You get 8 poles, linear phase, constant sine amplitude independent of freq, and very few parts. The PLL might be a bear, but other than that... Disclaimer: I haven't done this at such low frequencies, LTC chips might no go so low.

ak

Sep 9, 2010
16,102
6,219