5 Ways to Generate a Sine Wave

Sine waves are the most important AC waveform, since they are the basis for all other waves. Unfortunately, a sine wave isn’t as easy to generate as something like a square wave. Well, in this video I’ll show you a few different ways that you can generate sine waves for yourself. So without further ado, let’s dive in!

Square Wave Filtering

Like I said in the intro, sine waves aren’t the easiest to generate, but square waves are. I mean, something as simple as an astable 555 timer circuit could do the trick. Let’s take a look at the frequency make-up of a 50kHz square wave. To do this, we can pull-up the FFT on an oscilloscope. As you can see, the first frequency is 50kHz, which is the fundamental frequency. Afterwards, you’ll see several harmonics which diminish in amplitude as they go on. Each of these markers represents a sine-wave frequency that is present in the square wave signal.

If we want to retrieve the fundamental frequency’s sine wave, we just need to filter out all higher frequency components. Luckily, we have a few tools for this task. Let’s take a look at a basic low-pass RC filter. If we use a 3nF capacitor and a 1k resistor, we get a cutoff frequency of 53kHz, which is higher than the fundamental frequency of our square wave, but still lower than all of those harmonics. As you can see from the output of our filter, it isn’t exactly a sine wave. This is because our RC filter doesn’t have that steep of a cutoff.

Let’s take a look at an LC low-pass filter. These filters have a steeper cutoff, so we should get a more sine-like shape on the output. Let’s use an inductor of 470uH and a 22nF capacitor. As you can see, the resulting sine wave is much better than the one that we got from the RC filter. If you wanted to improve things even more, you could add another filter or two to better select the filtered frequency. Unfortunately, this filtering method isn’t the greatest for a selectable frequency, since you’d have to dynamically adjust the filter based on the input frequency.

Phase Shift Oscillators

We aren’t done with those low-pass RC filters yet. Each RC filter comes with an output phase shift thanks the to complex impedance. If you don’t know what I mean, let’s take a look at this specific filter which has a 560 ohm resistor and a 10nF capacitor. Let’s pass in a 50kHz sine wave to the input. As you can see, the output does not align with the input, and has been shifted. At this specific frequency, 50kHz, the sinewave gets shifted by roughly 60 degrees. You can find the phase shift of an RC low-pass filter with this equation: arctan(2 * pi * F * R * C).

All of this talk about phase shifts is important because we can use it in a sine wave oscillator. If we chain three of those RC filters together, we can get an oscillator. If we add a common-emitter amplifier, we now have a complete oscillator. If you don’t know what a common-emitter amplifier is, I recommend that you watch my previous video about BJT transistors. You can see how this circuit forms an oscillator by looking at the phase shifts. The three RC filters in series have a combined phase shift of 180 degrees at the oscillation frequency. The BJT amplifier has a phase shift of 180 degrees itself. This means we get a complete phase shift of 360 degrees from input to output, which is the same as 0 degrees. Other frequencies will not have that 180 degree phase shift through the filters, which means that the amplifier will amplify those frequencies at the wrong time, which will cause them to diminish.

If we use three of those filters, we get an output frequency of 58.7 kHz. Not too shabby. We can also make an op-amp version. For this test, I used the TL072 op-amp. As a side note, if you are in need of a negative and positive supply, you can wire the other op-amp on the package to act as a virtual ground. Anyways, I have it wired in an inverting configuration to give us a phase shift of 180 degrees. I’d also like to point out that the input resistor to the op-amp has a dual purpose of being a part of the RC filter and also the op-amp’s amplification stage. A 68k feedback resistor is enough to make the circuit oscillate. With all of this, we get an output of 31.9kHz. And I’d say that this is a rather handsome sine wave considering the simplicity of the circuit.

And as one final note regarding phase shift oscillators, you don’t have to use RC low-pass filters. You can really use anything that has a phase shift. You could use RC high-pass filters, or RL filters. You may also have 4 filter stages instead of just three. The possibilities are seemingly endless.

The Wien Bridge

The Wien bridge oscillator is another oscillator that relies on resistor and capacitor filters. It’s often drawn in a bridge shape. Which is why it is called the Wien bridge. It can be a bit confusing to look at it like this though, so let me break it down for you. Let’s just focus on the two important bits of the bridge. The top half is a series resistor and capacitor, the lower half is a parallel resistor and capacitor. These components together form a sort of filter as well. And just like the phase-shift oscillator from before, we are targeting a specific phase shift.

This time around, we are looking for the frequency at which the phase shift is zero degrees. We can solve for it by looking at the configuration as an impedance divider, similiar to a resitive divider. We can combine each pair of resistor and capacitor into a single impedance, with R1 and C1 being in series and R2 and C2 being in parallel. We can make a simplification where both resistances are the same and both capacitances are the same. And after quite a bit of algebra, we arrive at this equation. The frequency of oscillation is 1/(2 * pi * R * C). And at that frequency of oscillation, we get a gain of 1/3.

Let’s attach this to our op-amp, which is again the TL072. You’ll notice the other two resistors, which determine the gain on our non-inverting op-amp. These two resistors are the ones we initially neglected on the wien bridge. Either way, the selection of the resistors is difficult. Remember how I said that the gain of the wien bridge filters is one third, well that means that our op-amp will have to have a gain of three in order to cancel out those losses and maintain oscillation. Unfortunately, if you have too much gain, you will basically get a square wave on the output. It is far too difficult to get an exactly matched resistor for this case.

The most popular work around for this is a lightbulb. I unfortunately don’t have one with me, but the idea is that the lightbulb will increase its resistance when heating up, and decrease it after cooling. This should lead to an equilibrium where the gain is precisely chosen by the lightbulb.

Luckily, there are ways that you can do this without getting a lightbulb. The most practical is by using a JFET. A JFET in its linear region acts like a voltage controlled resistor. What we can do is setup a negative peak detecting circuit with a diode and a large capcitor. When the negative peak grows larger, it is stored in the capacitor, and the JFET becomes more resistive. This causes the peak to diminish and therefore reduces the resistance. Ideally, we should arrive at some sort of equilibrium.

The result that I achieved works decently well. The Wien bridge can be very stable and clean if setup right, but it is very difficult to do. Perhaps you could get better performance with a proper PCB and a different design.

LC Oscillators

Let’s take a look at a different kind of oscillator, which involves an inductor and a capacitor. I’ve brought you to the simulator to demonstrate what ideal behavior looks like. This configuration is often called an LC tank. Ideally, a parallel capacitor and inductor will shift their stored energy between each other. The frequency of this shift is given by the equation f = 1/(2 * pi * sqrt(L * C) ). And ideally they will continue this act forever. However, real life is not ideal, and there are parasitic resistances. This resistance will absorb some of the energy, and eventually the oscillation will dampen out.

In order to maintain the oscillation, we can add energy back into the LC tank in phase with the oscillation. There is a very famous circuit that can do this for us: the Colpitts oscillator. From the schematic you can find the LC tank. As you can see, the capacitor is divided up into two parts. This is important, since this forms the basis of our feedback. The signals on each capacitor will be opposite one another, and the ratio of the size of the capacitors determines just how large the base signal will be.

The other oddity in the circuit is L1, the collector inductor. This is often labeled as an RF choke on many versions of this circuit. From personal experience, this component makes it much, much easier to get the system to oscilate. Unfortunately, it does contribute to the resonant frequency, so make sure to take that into consideration if you need a precise frequency. Taking a look at the output, we can see that We are getting a 400kHz oscillating sine wave, with some distortion.

Let me also introduce a parallel to the colpitts oscillator: the hartley oscillator. It’s basically the same thing as the colpitts, but it splits up the inductor instead of the capacitor. I’d still recommend the colpitts over the hartley in most cases, since its easier to split up a capactior and it’s a bit easier to work with. But weigh up your options as needed.

Let’s take a look at an op-amp version. As you can see, the basic shape is still here. The LC tank is still divded up by the capacitors. On the output, we get a 180kHz output. It’s worth noting that the input of the op-amp has a much prettier sine wave in the case that you’d like to use that. You can also try to smooth the output of the op-amp by placing limiting diodes on the input as well. With this, we get a new frequency of 216 kHz and increased distortion.

Quartz Crystal Oscillators

Let’s take a look at crystal oscillators. And well, they aren’t all that different from the LC oscillators. Here is the equivalent circuit diagram of a crystal. It is basically a series resistor, inductor, and capacitor, all in parallel with an capacitor. Just like the LC circuits from before, a crystal will oscillate at a specific resonant frequency. For the following circuits, I will be using a 4MHz crystal.

The first design is a classic crystal oscillator circuit. R1 biases the resonant elements, and the two capacitors are split up to provide feedback to the transistor. The transistor will apply power in phase with the feedback given by the capacitors. The output from the circuit is distorted, but it is 4MHz on the dot. Which is certainly a good thing when you want the exact frequency as printed on the crystal.

It isn’t always like that though. Let’s take a look at a modified colpitts oscillator which uses a common-base amplifier. The resonant elements are all still here, and we get a sine output. However, the important thing that I want you to pay attention to is the frequency. We are getting 6.56 MHz on the output. So, just keep in mind that the crystal is not guaranteed to oscillate at its printed frequency, and other circuit elements may very well adjust the resonant frequency.

Let’s take a look at just one more crystal oscillator. It’s a JFET version of a Pierce oscillator. I’d say that this is the best crystal oscillator circuit out of the three that I tested in this video. The output is a clean 4MHz sine wave, with decently low distortion. The only drawback is the annoyingly high voltage needed: 22 volts.

That should just about cover it for basic sine wave oscillators. If you’ve enjoyed this video and learned something new, please consider subscribing so that you can see my future videos. Also, visit my buymeacoffee page, with you support I can keep making these videos. I’d like to thank Mr. devNull and Cognisent for being long-time channel supporters. Thanks for watching, have a good one!

 Share!