# Correct way to convert square signal to sine waveform

I have a square form signal that can change frequency from 100kHz to 200kHz (more precisely, the '1' is coded by 200kHz part (2 oscillations) and '0' is coded by 100kHz). The amplitude is about 2.5V. How can i change the waveform of the signal to sine, but preserve frequency changing? I think that the most common way is to use two integrators: passive (or active) to convert square to saw and then active (based on op-amp) to convert saw to sine. I'm not an electrical engineer, and this solution I've find by reading articles on the net. Is this correct or may be exists more correct or easier solutions? Just need to determine if I'm going the correct way.

• Filter out everything but the first harmonic, i.e. 250kHz lowpass filter. Commented Nov 30, 2013 at 11:40
• @IgnacioVazquez-Abrams that won't work too well because the OP only wants to send two cycles at 200kHz and 1 cycle at 100kHz. Commented Nov 30, 2013 at 17:31

Is this correct or may be exists more correct or easier solutions?

DDS is probably a good way. The AD9837 is one of the simpler devices to use and because of its flexibility I'm suggesting it.

It can generate sine waveforms of the frequency you require with ease and it is programmable so that these waveforms can be changed on the fly. In fact for your application it neds to be programmable because your modulation signal needs to control the device by an SPI bus probably using a small microcontroller. I'm aware that you are not an electrical engineer so this solution may not be the most convenient but, if you are looking for flexibility and accuracy I think this is probably the best solution.

On a slightly different note, you are proposing, for say a 1, 0 sequence, 2 cycles of 200kHz followed by one cycle of 100kHz - I would have the changeover at the peak of the waveform in order to minimize harmonic disturbances: -

The red circle indicates the point where the waveform switches from one frequency to another and this will give rise to more harmonics than switching at the peak of the waveform as shown in the lower diagram.

This of course means less filtering. Either method can be done with DDS.

• I think DDS would be a good term to define explicitly in this answer (hint: en.wikipedia.org/wiki/Direct_digital_synthesizer). Commented Nov 30, 2013 at 23:01
• @Shamtam that's as good as defined, thanks for taking the time to read and think. Commented Nov 30, 2013 at 23:04
• @Andyaka AD9833 done this for me. Thanks! Commented Dec 4, 2013 at 14:44
• @Darkkey coolio Commented Dec 4, 2013 at 14:46

This could be done with a fast microcontroller and a 16 bit DAC. (A few microcontrollers have built-in DAC's but they tend to be more often 10 or 12-bit).

You would synchronize with your input signal by feeding it into a digital interrupt pin, and output a sine wave (stored in Flash) to the DAC. The sine wave table would be adjusted for your 200 KHz/100 KHz variation.

Since 200 KHz corresponds to 5 µs, and you will want to output several 16-bit samples to the DAC during each cycle, you are going to want to use a microcontroller with at least a 16-bit data path and a fast instruction rate, such as the PIC24EP64GP202, which runs at 70 MIPS (instruction cycle time of 14 ns) and is available in a DIP package for prototyping.

The limited factor there may be how fast you can write to the DAC; you will want to use an SPI rather than I2C interface since SPI can run several 10's of MHz and I2C is limited to 100 KHz (standard rate) or 400 KHz (extended rate).

If you integrate square to sawtooth, you will need to also change the integrator gain (switch a resistor according to input=0 or 1) otherwise the sawtooth amplitude will be halved at the higher frequency.

There used to be a trick with an opamp and resistors and diodes in the feedback circuit (deliberate "soft clipping") to get an approximation to a sinewave from a sawtooth input. Naturally this only works well for a constant amplitude sawtooth.

If you can find an ICL8038 datasheet, it might show how that chip's internal circuitry accomplished the task.

It is only an approximate sinewave, roughly a couple of percent harmonic distortion : if that's not good enough, then it at least makes the filtering job easier.