Multiply and Sum Correlator
Run the Multiply and Sum Correlator MicroSim Fullscreen
You can include this MicroSim on your website using the following iframe:
1 2 | |
About This MicroSim
Correlation sounds like a sophisticated operation. It is two lines of code:
1 2 3 | |
Multiply the two signals sample by sample; add up the products. That is the entire mechanism the DFT is built from, and this sim runs it one sample at a time so you can watch the total behave.
When the frequencies match, the two waveforms are positive together and negative together. Every product is positive — a negative times a negative is still positive — so the running total climbs steadily and never backs up.
When they do not match, the waves drift in and out of step. Sometimes the product is positive, sometimes negative, and the contributions cancel. The total wanders near zero and ends there.
That difference is the entire basis of frequency detection.
How to Use
- With the default matching setup, press Step one sample repeatedly. Watch the product readout. Are any of them negative? Why not?
- Press Run to completion and note the final normalized correlation.
- Change Captured signal to Offset by +250 Hz and press Reset, then run again. Watch the bar swing both ways and end near zero.
- Try Offset by +500 Hz. Same result — and that is the point. Every non-matching frequency gives near zero, not just one of them.
- Move the Test frequency slider and repeat. The behavior depends on the relationship between the two frequencies, not on their absolute values.
Why the Offsets Are 250 Hz
The window holds 32 samples at 8 kHz, so the bin spacing is \(f_s / N = 8000 / 32 = 250\) Hz. Frequencies separated by a whole multiple of that spacing are exactly orthogonal over this window — their products cancel to precisely zero rather than merely nearly zero. The offsets are chosen to land on those exact nulls.
Lesson Plan
Grade Level
Undergraduate (college junior/senior)
Duration
12-15 minutes
Prerequisites
- A signal can be stored as an array of samples
- Multiplication of signed numbers
Learning Objective
Students will be able to calculate a multiply-and-sum correlation sample by sample and demonstrate how the running total behaves differently for a matching versus a non-matching test frequency.
Activities
- Sign analysis (4 min): Stepping through the matched case, students explain why every single product is non-negative.
- The mismatch (5 min): Students run an offset case and identify the samples where the product turns negative and cancels earlier gains.
- Predict the total (4 min): Before running, students predict the final normalized value for a matched pair (near 1) and a mismatched pair (near 0).
Assessment
Ask: "Without running the sim, what will the running total look like halfway through if the test frequency is exactly one bin away from the signal? Sketch it."
Related Resources
References
- Cross-correlation — the general operation this sim performs.
- Orthogonality — why non-matching sinusoids cancel to zero over a full window.