Square wave to Sine wave (variable frequency)

Thread Starter

teliocide

Joined Sep 26, 2013
126
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
 

#12

Joined Nov 30, 2010
18,224
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.
 

Thread Starter

teliocide

Joined Sep 26, 2013
126
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.???????
 

MikeML

Joined Oct 2, 2009
5,444
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.
 

AnalogKid

Joined Aug 1, 2013
10,986
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
 

dl324

Joined Mar 30, 2015
16,839
The sine wave does not have to be perfect.
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.

http://www.allaboutcircuits.com/vol_2/chpt_8/2.html
 

Nykolas

Joined Aug 27, 2013
115
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
 

wayneh

Joined Sep 9, 2010
17,496
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.
 

Brownout

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

ScottWang

Joined Aug 23, 2012
7,397
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.

700Khz-Sqr2Sin_ScottWang.gif
 

WBahn

Joined Mar 31, 2012
29,976
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.
 

dl324

Joined Mar 30, 2015
16,839
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.
 

WBahn

Joined Mar 31, 2012
29,976
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.
 

wayneh

Joined Sep 9, 2010
17,496
Thanks Wayneh,
Sounds very feasible ....... any suggested circuits?
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.
 

Alec_t

Joined Sep 17, 2013
14,280
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).
 

dl324

Joined Mar 30, 2015
16,839
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.
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.
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.
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.
 

AnalogKid

Joined Aug 1, 2013
10,986
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
 
Top