Skip to content

Signal Example — Dot Product & Frequency Detection ​

Interactive demo showing the single core idea behind the Discrete Fourier Transform (DFT): multiplying a signal by a test sinusoid and summing the result.

What it shows ​

RowPlotDescription
1Signal + Test sinusoid(s)The signal (blue) and the sine test sinusoid (red) overlaid. When Complex is on, the cosine test (green) also appears.
2Sine productSignal × sine test sinusoid, with the dot product value and Freq/Phase match status shown.
3Cosine productSignal × cosine test sinusoid (visible only when Complex is on).

Key Concept ​

The dot product measures how similar two signals are — multiply them point-by-point and sum the results:

The DFT uses exactly this idea to answer "how much of frequency f is in this signal?" by setting one of the signals to a test sinusoid:

Freq match, Phase match → product is all-positive → large sum → large dot product.

Freq mismatch → product alternates +/- → cancels to near zero.

Phase mismatch (90°) → product alternates even at matching frequency → dot product ≈ 0.

Why "complex"? ​

The sine-only dot product is phase-sensitive — it fails when the signal and test sinusoid are 90° out of phase. The DFT solves this by computing two dot products — one with a sine and one with a cosine — and combining them into a single phase-independent measure:

The sine captures the "how much matches my phase" part. The cosine captures the "how much is 90° away" part. Together, they capture all the energy at that frequency, no matter the phase. Toggle Complex on and drag the Phase slider to see this in action.

Controls ​

ControlRangeDescription
Signal Freq1–40 HzFrequency of the signal
Amplitude0.1–2Signal amplitude — dot product scales proportionally
Phase (°)0–355°Signal phase offset — try 90° at matching frequency
Test Freq0.5–60 HzThe DFT "probe" frequency
Noise0–1Additive Gaussian noise
ComplextoggleAdd cosine probing for phase-independent magnitude

Things to Try ​

  1. Frequency match: set Signal Freq = Test Freq = 10 Hz → product all-positive, dot product ≈ amplitude.

  2. Frequency mismatch: move Test Freq to 15 Hz → product alternates, dot product ≈ 0.

  3. Phase sensitivity: set both frequencies to 10 Hz, then drag Phase to 90° → dot product drops to ≈ 0 even though frequencies match.

  4. Complex to the rescue: with Phase still at 90°, toggle Complex on → the magnitude (purple) recovers to ≈ amplitude. Drag Phase anywhere — the magnitude stays constant.

  5. Amplitude scaling: raise Amplitude to 2 → dot product doubles. The test signal is always ±1; the result reflects only the signal amplitude.

  6. Noise: add noise → individual products become noisy but the sum (dot product) is still large at the matching frequency (averaging suppresses noise).

See Also ​

Code ​

julia
using EegFun
EegFun.signal_example_dotproduct()