Dsp-pitch-detection-autocorrelation

Input Signal

Fig 1: Raw Audio Signal

Autocorrelation Output

Fig 2: Autocorrelation Peak Detection


Project Overview

This project implements the Autocorrelation Function (ACF) to detect the fundamental frequency (pitch) of audio signals. It is a core concept in Digital Signal Processing (DSP) used in speech recognition and music analysis. The system analyzes time-domain signals to find repeating patterns and calculates the pitch with high accuracy.

Technologies & Algorithms

How it Works

1. Pre-processing: Noise reduction and signal normalization.
2. Autocorrelation: Calculating the correlation of the signal with a delayed copy of itself.
3. Peak Detection: Identifying the first major peak (lag) to determine the time period (T).
4. Frequency Calculation: F = 1/T.

Code Snippet

import numpy as np
import matplotlib.pyplot as plt

def autocorrelation(x):
    result = np.correlate(x, x, mode='full')
    return result[result.size // 2:]

# Calculate Pitch
def get_pitch(signal, fs):
    corr = autocorrelation(signal)
    # Find the first peak after zero lag
    d = np.diff(corr)
    start = np.where(d > 0)[0][0]
    peak = np.argmax(corr[start:]) + start
    return fs / peak