# Sine to square wave conversion

Discussion in 'Electronic Design' started by Sandeep, Nov 4, 2005.

1. ### SandeepGuest

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

2. ### SandeepGuest

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

A filter?

Leon

4. ### JonGuest

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

5. ### BrianGuest

Here are some schematics of a Low-pass and a Band-pass filter, for 1 KHz.
http://www.fncwired.com/LowpassEx/

Brian

6. ### John LarkinGuest

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

7. ### Guest

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.

8. ### Jim ThompsonGuest

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

9. ### Guest

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.

10. ### John LarkinGuest

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
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

11. ### John LarkinGuest

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

12. ### JonGuest

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

13. ### Guest

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

14. ### John LarkinGuest

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

15. ### John WoodgateGuest

I read in sci.electronics.design that wrote (in
You don't NEED a band-pass filter, because you are trying to eliminate
only frequencies higher than the one you want. So a high-Q low-pass
filter, peaked at 1 kHz, would be good. That gives you 'gain' at the
frequency you want, while it attenuates the harmonics in proportion to
their order.

16. ### Jim ThompsonGuest

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

17. ### JoergGuest

Hello Jim,
Why would you want to vary the excitation frequency on a sonar (the
civilian versions, of course)? If it was a long range job where return
signals become mushy in the distance you'd need a tracking filter that
keeps the low pass limit constant but reduces the high cut-off with depth.

Regards, Joerg

18. ### John LarkinGuest

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

19. ### John LarkinGuest

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

20. ### JoergGuest

Hello John,
That would be like debating whether a seal is more of a land animal or a
sea animal ;-)

Regards, Joerg