# Sine to square wave conversion

• posted

Hi all, I want to know how to convert a 1KHZ square wave into a stable sine wave .Please can anybody help me out Many Thanks Sandeep

• posted

Sorry the subject is Square to sine wave conversion. Many thanks

• posted

A filter?

Leon

• posted

A few methods: ~ Use a phase locked loop chip that has sine wave output capability. Lock the PLL to the input square wave. ~ Run the square wave through a sharp low pass filter to remove the harmonics. In determining the filter requirements you must decide how much distortion you can tolerate. A square wave has only odd harmonics, so the 1st harmonic that is present is the 3rd. The harmonic amplitudes are in the ratio 4/Pi (Fundamental) 4/(3Pi) (3rd harmonic) , 4/(5Pi), etc. ~ If the output sine wave must be in phase with the fundamental component of the square wave, then use a bandpass filter with a center frequency of 1 KHz. The phase lags and leads of this filter will cancel at the center frequency. For a given distortion, the required order of the bandpass filter will be twice the required order of the lowpass filter . Regards, Jon

• posted

Huh?

A simple high-Q L-C, or equivalent 2nd order bandpass, can easily filter better than a 10-pole lowpass.

in-----------r--------+-------+-------out | | | | L C | | | | | | gnd gnd

John

• posted

All depends on what you mean by "better".

Q? then you might be right.

But if you mean steepness in the transition band, no, you are very wrong. You get 20 dB/decade (power) slope per pole or zero. If you want it steeper, you need more poles and zeros. Since a bandpass has two transition bands, the overall order needs to be twice that of a highpass or lowpass with only one transition band in order to have the same slopes.

• posted

We're talking about attenuating overtones at 3x, 5x, 7x, etc the center frequency, not the sharpness of the response around the center frequency itself.

• posted

Here are some schematics of a Low-pass and a Band-pass filter, for 1 KHz.

Brian

• posted

Eh? A little knowledge is a dangerous thing. The 20dB/decade is related to bandwidth, so a very narrow (high Q) BP filter will fall much faster than an LP.

...Jim Thompson

```--
|  James E.Thompson, P.E.                           |    mens     |
• posted

If the square is perfect and has no 2nd harmonic, my "10-pole" statement may be a bit of an exaggeration... 3^10 is a pretty big number. But a reasonably high-Q single-L-C bandpass will massively out-filter a 2nd order LPF. As you note, the dropoff of a bpf is relative to its bandwidth, not its cf. That makes sense, as a bandpass is classically synthesized by *shifting* a lowpass filter.

A 10 Hz wide LC bandpass, centered at 1KHz, Q=100, sure has a steeper slope than 20 dB/decade! Actually, it approaches 20 dB/decade far out from the peak, but the fun's over by then.

Of course, you could make a "bandpass" by cascading a lowpass with a highpass, in which particular case cs is right, but that would be a silly thing to do here.

John

• posted

Exactly. And the narrower the bandpass, the better we attenuate those harmonics. The attenuation slope past 3f won't be high, but the ratio of cf amplitude to 3f+ amplitude increases with Q, without limit.

Just graph the amplitude response of a simple R-L-C bandpass of Q=100.

John

• posted

Jim, You are right in that the initial transition slope of a bpf will be steeper than for the same type (Butterworth, Chebyshev, etc) lpf. However, the ultimate slope of a bpf wil be equal to n*20/2 db/decade for a bpf, and n*20 db/decade for a low pass. Regards, Jon

• posted

Okay, you've convinced me of a possibility I hadn't looked into carefully enough.

If the frequency is accurate and stable enough and the components accurate and temperature stable enough and then this is probably the way to go.

If 1khz was meant more approximately, or environemental conditions or design for manufacturing makes precise tuning undesirable, might it be advantageous?

• posted

Right, a 2-pole high-Q bandpass can get tricky. But you can design a higher-order bp filter, 4 pole maybe, that's reasonably flat on top, to allow for modest source frequency and parts tolerances, and still get the attenuation advantages of a true bandpass.

Of course, it doesn't make sense to build a bandpass by cascading hp and lp sections... we don't need a highpass section here, just a lowpass that will pass the fundamental and whack the 3rd and up.

It gets interesting to make a sine from a square wave over a wide frequency range. A pll or a tracking filter come to mind. Switched-capacitor filters, either bp or lp, are compact and easily tuned, but need some modest anti-aliasing passive filters before and after to avoid complications.

Or a pll multiplier feeding a dds synthesizer!

John

• posted

The way I tuned my sonar BP (gm-C) filters was to insert a square wave at the desired center frequency and then vary gm with a DAC until the phase flipped from +90° to -90° (center frequency).

I wonder if, in similar fashion, one might implement a tracking filter that automatically follows the input square wave frequency ??

...Jim Thompson

```--
|  James E.Thompson, P.E.                           |    mens     |
• posted

I did a filter once, connected to a multiplier as a quadrature phase detector, so it would have zero volts out at 90 degrees phase shift. That was used to compare the filter's input to output and tune a varicap for zero multiplier output. The filter inherently produced 90 degrees shift at its center frequency, so ta-daah!

John

• posted

There is some grounds for debating whether such a filter, a lowpass with a big gain peak just below Fc, is indeed a "bandpass" filter.

This

in-------R-------L--------+--------out | | C | | gnd

can be a Butterworth (or worse), or can have a huge gain peak just before it falls off. It does have a 90 degree phase lead at the peak, which makes it handy for servo tracking the input frequency. A true

2-pole RLC bandpass has zero phase shift at Fc.

John

• posted

I can't comment. But the client's engineers were clearly VERY top notch.

...Jim Thompson

```--
|  James E.Thompson, P.E.                           |    mens     |
• posted

For mine I'd used the classic PFD, except I treated the CP output as a logic signal ;-)

...Jim Thompson

```--
|  James E.Thompson, P.E.                           |    mens     |
```--