## Frequency power spectrum of Sine, Square, Sawtooth, and Triangle Waveforms

Today I came across an interesting MATLAB code example today from the University of Maryland: http://terpconnect.umd.edu/~toh/spectrum/HarmonicAnalysis.html. Prof. Tom O’Haver did a wonderful job with this example, but I had some problems with MATLAB crashing while running it. The program may be more resource-intensive than it appears.

**Sine wave:**

The frequency analysis of a basic sine wave shows that it consists of only a single frequency at 250 Hz.

**Square wave:**

A square wave with the same frequency has its highest peak at the fundamental frequency and the power has these harmonics:

**Sawtooth Wave:**

A sawtooth wave includes both odd and even harmonics, and the power reduces by half at each harmonic.

**Triangle Wave:**

A triangle wave has a similar set of harmonic frequencies to a square wave (odd harmonics), but each one is distributed over a wider range rather than focused at a specific frequency. At each odd harmonic, the power is reduced significantly.

A triangle wave was not included in the original post, but I added one for my own purposes. In MATLAB, a triangle wave is created using the *sawtooth* function as shown:

*y=sawtooth((f1+f2/100)*x,.5);*