0
0
RosConceptBeginner · 3 min read

Cross Correlation in Signal Processing: Definition and Example

In signal processing, cross correlation measures how similar two signals are as one signal slides over the other. It helps find time delays or matching patterns between signals by calculating a similarity score at each shift.
⚙️

How It Works

Imagine you have two sound recordings and want to see if one appears inside the other, but maybe shifted in time. Cross correlation slides one signal over the other step by step and checks how much they match at each position. The higher the match, the more similar the signals are at that shift.

This is like sliding a transparent sheet with a pattern over another pattern and seeing where they line up best. The result is a new signal showing similarity scores for each shift, helping you find where the signals align.

💻

Example

This example shows how to calculate cross correlation between two simple signals using Python and NumPy.

python
import numpy as np
import matplotlib.pyplot as plt

# Define two signals
signal1 = np.array([1, 2, 3, 4, 2])
signal2 = np.array([0, 1, 0.5])

# Compute cross correlation
cross_corr = np.correlate(signal1, signal2, mode='full')

# Print the result
print('Cross correlation:', cross_corr)

# Plot signals and cross correlation
lags = np.arange(-len(signal2)+1, len(signal1))
plt.figure(figsize=(8,4))
plt.subplot(1,2,1)
plt.title('Signals')
plt.plot(signal1, label='Signal 1')
plt.plot(signal2, label='Signal 2')
plt.legend()

plt.subplot(1,2,2)
plt.title('Cross Correlation')
plt.stem(lags, cross_corr, use_line_collection=True)
plt.xlabel('Lag')
plt.tight_layout()
plt.show()
Output
Cross correlation: [0. 1. 2.5 4. 7. 8. 4. ]
🎯

When to Use

Cross correlation is useful when you want to find if one signal appears inside another or to measure the time delay between two signals. For example:

  • In audio processing, to find echoes or repeated sounds.
  • In radar and sonar, to detect objects by matching received signals with sent pulses.
  • In communications, to synchronize signals or detect patterns.
  • In neuroscience, to study timing relationships between brain signals.

Key Points

  • Cross correlation compares two signals by sliding one over the other.
  • It produces a similarity score for each possible shift (lag).
  • High values indicate strong similarity or alignment at that lag.
  • It helps find delays, echoes, or matching patterns in signals.

Key Takeaways

Cross correlation measures similarity between two signals as one shifts over the other.
It helps find time delays or matching patterns in signals.
Use it in audio, radar, communications, and neuroscience to detect alignment or echoes.
The output shows similarity scores for each lag, with higher values meaning stronger matches.