A harmonic analysis calculator works out the amplitude and phase of the sine and cosine components that make up a periodic signal, using the discrete Fourier transform (DFT). You enter a list of sampled values (a waveform), and it returns the frequency, amplitude, and phase of each harmonic, letting you see which frequencies dominate the signal.
Formula
For a set of n equally spaced samples x[0], x[1], …, x[n−1], the k-th harmonic (frequency k/n cycles per sample) has amplitude and phase given by:
Amplitude Ak = (2/n) × √( (Σ x[i]·cos(2πki/n))² + (Σ x[i]·sin(2πki/n))² )
Phase φk = atan2( −Σ x[i]·sin(2πki/n), Σ x[i]·cos(2πki/n) )
where the sums run from i = 0 to n−1, and atan2(y, x) gives the angle in radians between −π and π. The factor 2/n normalizes the amplitude so that a pure sine wave of amplitude A yields Ak = A. The DC component (k = 0) is simply the average of the samples.
Worked Example
Take the default input: 6 samples: 1, 0.5, −0.5, −1, −0.5, 0.5. This is one cycle of a triangle-like wave.
- n = 6, so the fundamental frequency is 1/6 cycles per sample.
- DC component = (1 + 0.5 − 0.5 − 1 − 0.5 + 0.5)/6 = 0/6 = 0.
- For k = 1: compute the cosine sum: Σ x[i]·cos(2π·1·i/6) for i=0..5: 1·1 + 0.5·0.5 + (−0.5)·(−0.5) + (−1)·(−1) + (−0.5)·0.5 + 0.5·(−0.5) = 1 + 0.25 + 0.25 + 1 − 0.25 − 0.25 = 2.0.
- Sine sum: 1·0 + 0.5·0.866 + (−0.5)·0.866 + (−1)·0 + (−0.5)·(−0.866) + 0.5·(−0.866) = 0 + 0.433 − 0.433 + 0 + 0.433 − 0.433 = 0.
- Amplitude A₁ = (2/6) × √(2.0² + 0²) = (1/3) × 2 = 0.6667.
- Phase φ₁ = atan2(0, 2.0) = 0 radians.
So the first harmonic is a cosine wave of amplitude 0.6667 and phase 0. The calculator shows the same result: a1 = 0.6667, p1 = 0.
Assumptions
- The input samples are equally spaced in time (or space).
- The signal is periodic with period equal to the total sampling window.
- The samples are real numbers (no complex input).
- The Nyquist limit applies: you can only resolve frequencies up to half the sampling rate.
What Harmonic Analysis Is Used For
Harmonic analysis is the mathematical tool that breaks a complex periodic waveform into simple sine and cosine waves. It is fundamental in electronics (analyzing distortion in audio amplifiers), power systems (measuring harmonic distortion in AC lines), acoustics (identifying the overtones of a musical note), and vibration analysis (finding resonant frequencies in machinery). A harmonic analysis calculator typically computes the discrete Fourier transform (DFT) or the fast Fourier transform (FFT) when the number of samples is a power of two.
For example, a 60 Hz power line might show a 60 Hz fundamental, plus smaller components at 120 Hz, 180 Hz, etc. The amplitudes tell you how much distortion is present. In audio, a pure tone of 440 Hz (A4) will show a single peak at 440 Hz; a violin playing the same note will show additional peaks at 880 Hz, 1320 Hz, etc., which give it its characteristic timbre.
How to Read the Results
The calculator above gives you the amplitude and phase of the first harmonic (k=1) only, but the same formula applies for any k. The amplitude tells you the strength of that frequency component relative to the original signal. The phase tells you the time shift of that component relative to the start of the sampling window.
If you enter a pure sine wave of amplitude 2, you will get A₁ = 2. If you enter a square wave, you will get odd harmonics (1st, 3rd, 5th…) with amplitudes decreasing as 1/k. The DC component (average) is often useful to know if the signal has a constant offset.
Remember that the frequency is given in cycles per sample. To convert to physical frequency (Hz), multiply by the sampling rate. For example, if you sampled at 1000 samples per second, a frequency of 1/6 cycles per sample corresponds to 1000/6 ≈ 166.7 Hz.
Common Mistakes and Limits
- Not removing the DC offset: If your signal has a nonzero average, the DC component will appear as a large peak at frequency 0, which can obscure nearby low frequencies. Subtract the mean before analysis if you only care about AC components.
- Ignoring the Nyquist frequency: The DFT only gives meaningful results up to half the sampling rate. Frequencies above that are aliased (folded back) and appear as false lower-frequency components.
- Using too few samples: A short window gives poor frequency resolution. To distinguish two close frequencies, you need a long enough sampling window (roughly 1/Δf samples).
- Assuming the signal is periodic: The DFT assumes the signal repeats exactly. If it doesn’t, you get spectral leakage, where energy spills into adjacent frequency bins. Applying a window function (e.g., Hann) reduces this but changes the amplitude slightly.
- Phase wrapping: Phase values are given between −π and π. If you see a jump from π to −π, it’s the same phase, not a discontinuity.
The formula works for any real-valued samples, but for very large datasets (thousands of points), the direct DFT is slow; the FFT algorithm is much faster. This calculator is meant for small lists to illustrate the concept, not for heavy signal processing.
How to Choose a Harmonic Analysis Tool
If you are analyzing real-world signals, a general-purpose calculator like this one is only a starting point. For practical work, you would use software that implements the FFT, such as Python’s NumPy, MATLAB, or a digital oscilloscope with FFT functionality. When choosing a tool, consider:
- Whether it handles complex inputs (for quadrature signals).
- Whether it applies window functions automatically.
- Whether it outputs amplitude in RMS or peak units.
- Whether it can handle non-uniform sampling (rare, but some data sets have gaps).
For educational purposes, a simple DFT calculator like this one helps you understand the math. For engineering, use a dedicated FFT library. Always verify the scaling: some tools divide by n, others by n/2, so amplitudes may differ by a factor of 2.
Frequently Asked Questions
What is the difference between harmonic analysis and Fourier analysis?
They are essentially the same thing. Harmonic analysis is the broader mathematical field, but in signal processing, it refers to decomposing a signal into sinusoids. Fourier analysis is the specific technique using the Fourier transform. A harmonic analysis calculator typically implements the discrete Fourier transform.
Why do I get a large value at frequency 0?
That is the DC component, the average value of your signal. If your waveform is not centered around zero (e.g., all positive values), the DC offset will dominate. Subtract the mean from each sample before analysis to remove it.
Can I use this calculator for audio analysis?
Yes, in principle, but you need to enter the raw samples of the audio waveform. For a typical audio file with 44,100 samples per second, you would need to enter thousands of numbers, which is impractical here. Use an audio analysis tool that reads the file directly.
What does the phase tell me?
Phase tells you the time offset of that frequency component relative to the start of your sampling window. It matters when you want to reconstruct the signal or compare components across different signals. For magnitude-only analysis (like a spectrum analyzer), you can ignore phase.
How do I get the frequency in Hertz?
Multiply the cycles-per-sample value by the sampling rate. For example, if you sampled at 1000 Hz and the fundamental is 1/6 cycles per sample, the frequency is 166.7 Hz. Always know your sampling rate before starting.
What is spectral leakage and how do I avoid it?
Spectral leakage happens when the signal is not exactly periodic within the sampling window, causing energy to spread across many frequency bins. To reduce it, apply a window function like Hann or Hamming to the samples before the DFT. This widens the main peak but reduces the side lobes. The trade-off is slightly lower amplitude accuracy.
Related
Formula used
in list | Sampled values (comma-separated) | 1, 0.5, -0.5, -1, -0.5, 0.5 | 0 out n | Number of samples | - | count | 0 out fund | Fundamental frequency (cycles/sample) | - | 1 / n | 4 out dc | DC component (average) | - | mean | 4 out a1 | Amplitude of 1st harmonic | - | 2 * sqrt((sum(v*cos(2*pi*1*i/n)))^2 + (sum(v*sin(2*pi*1*i/n)))^2) / n | 4 out p1 | Phase of 1st harmonic (radians) | - | atan2(-sum(v*sin(2*pi*1*i/n)), sum(v*cos(2*pi*1*i/n))) | 4
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation with the constants and conversion factors written on the page, rounded as each result states. See method and constants, the disclaimer or report an error.
More in this section
- QPP Calculator Canada: How It Works & How to Use It
- PPP Calculator World Bank: How It Works & How to Use It2,000.00
- PPP Calculator: India vs USA Cost Comparison1,000.00 USD
- PPP Calculator USD to INR: How It Works2,335 INR
- PPP Calculator India vs Dubai: Real Cost Comparison8,954.58 AED
- PPP Calculator India vs UK: Real Cost Comparison103.63 GBP