Scaling, stretching and shifting sinusoids

3 min read Original article ↗

This is a brief and simple [1] explanation of how to adjust the standard sinusoid to change its amplitude, frequency and phase shift. More precisely, given the general function:

We’ll see how adjusting the parameters A, w and \theta affect the shape of . Each section below covers one of these aspects mathematically, and you can use the demo at the bottom to experiment with the topic visually.

Scaling is conceptually the simplest change; we adjust A to increase or decrease the amplitude (maximal height) of . Setting will make the y value twice as large (in both the positive and negative direction) as the original function.

Stretching

Stretching changes the frequency of , which is inverse proportional to its period. The baseline function has a period of , meaning it repeats every . In other words, for any x.

If we set , we get . This function repeats itself twice as fast as , because x is multiplied by 2 before being fed into the sinusoid. If x changes by , the sinusoid’s input changes by . Therefore, the period of is , the period of is and so on. [2]

More generally, the period of is . Play with the demo below to see this in action, by changing w and observing how the waveform changes.

If we know the period we want, we can easily calculate the w that gives us this period:

Shifting

The final parameter we discuss is \theta; it’s called the phase of the sinusoid. In the baseline , \theta=0. The sinusoid is 0 at , achieves its positive peak at , crosses 0 again at , negative peak at and returns to its original position at where the repetition begins.

By adding a non-zero \theta, we don’t affect the sinusoid’s amplitude or frequency, but we do shift it right or left along the x axis. For example, suppose we use the function with . Then when , we have , so the sinusoid is already at its positive peak; at , the sinusoid crosses 0 into the negatives, etc. Everything happens earlier (by exactly the value of ) than in the baseline sinusoid. In other words, we’ve shifted the function left by . Similarly, when \theta is negative, everything happens later, and the function is shifted right.

Putting it all together

We’ve now gone over all the parameters for the function:

  • A controls the scaling factor (amplitude).
  • w is the frequency and controls the repetition period
  • \theta controls the phase - how much the sinusoid is shifted left or right

Use the demo below to adjust these parameters and observe their effect on the sinusoid:

Your browser does not support the HTML5 canvas tag.

[1]The math level of this post is high-school, at best. My main goal here is to test how to integrate interactive demos into my blog posts.
[2]This can be a bit counter-intuitive at first; we scale w by 2, but the period scales by half. Why? The reason is that w affects the sinusoid’s domain, while the period is a property of its range. Therefore, an inverse relation is reasonable, once we put more thought into it. In fact, w is often called the angular frequency of the sinusoid, and frequency is inverse proportional to the period.