Simplified Phase Vocoder
Implementation of a simplified phase vocoder system in MATLAB to tune vocal input to the C Major scale. BE 3010 (Signals & Systems).
Overview
This project was a simple attempt at pitch correction in MATLAB: take a recording of a C Major scale sung slightly off-key and move each note toward its intended pitch.
Because the voice changes over time, the system analyzes short, overlapping segments using the Short-Time Fourier Transform (STFT). It detects a pitch in each segment, shifts the spectrum, and reconstructs the recording.
Methods
The implementation uses a simplified phase-vocoder approach.
Signal Analysis:
The input audio signal was first converted to mono and segmented into overlapping frames. An STFT window size of N=2048 was selected as a practical trade-off between frequency resolution and time resolution. At a sampling rate of fs=44.1 kHz, a 2048-sample window spans approximately 46 ms, long enough to assume the signal is locally stationary. The corresponding frequency resolution is 21.5 Hz, which is sufficient to resolve harmonic structure in vocal signals. A Hanning window was applied to each frame before applying the Fast Fourier Transform (FFT) to reduce spectral leakage. A hop size of N/4 (512 samples) resulting in 75% overlap was chosen to ensure smooth reconstruction.
Pitch Detection & Modification Pipeline:
The pitch correction logic was carried out through three steps:
- Peak Detection: The algorithm identifies the index corresponding to the maximum magnitude in the spectrum and calculates the current pitch.
- Quantization: The system compares the current frequency against a predefined array of target frequencies corresponding to the C Major scale starting at C4 (261.63 Hz, 293.66 Hz, …). The nearest target frequency is selected, and a shift factor is derived.
- Spectral Remapping: The magnitude spectrum is frequency-warped by mapping the energy from original bins to new bins based on the shift factor. The original phase was kept while the magnitude spectrum was shifted. This simplified the implementation but introduced audible artifacts.
Noise Reduction Strategy:
A two-stage filtering strategy was implemented to reduce artifacts and background noise:
- Harmonic Masking: A “comb filter” mask was generated in the spectral domain. Based on the target frequency, the mask preserves frequencies at harmonics of the fundamental frequency (up to 8 harmonics) and attenuates other frequencies with a bandwidth of ±60 Hz.
- Global Band-Pass Filter: A 4th-order Butterworth band-pass filter with cutoffs at 100 Hz and 3500 Hz was applied to preserve the fundamental frequency and its harmonics while attenuating background noise.
Signal Reconstruction:
The modified frequency spectrum was converted back to the time domain using the Inverse FFT. A second Hanning window was applied to the output frame before reconstructing the continuous signal via the overlap-add method.
Results
The pitch correction system was evaluated with spectral analysis and by inspection of the processed vocal recording. The spectrograms of the input signal and the pitch-corrected output demonstrated successful tuning of the input to the target C Major scale, with signal attenuation between harmonic partials.
The hybrid noise reduction process effectively reduced background noise but left vertical striations across the spectrum, likely corresponding to phase discontinuities at STFT frame boundaries. The processed audio signal had noticeably lower quality and clarity than the original signal, with “robotic” artifacts corresponding to phase discontinuities introduced by the simplified approach of preserving original phase information rather than explicitly propagating phase through frames.
What I’d improve
The corrected notes were closer to the intended pitches, but the recording sounded more robotic. A fuller phase-vocoder implementation would track phase across frames instead of simply preserving it. I’d also look at preserving the vocal spectral envelope so that shifting pitch changes less of the voice’s character.
Skills Used
- Programming: MATLAB, Signal Processing Toolbox
- Signal Processing Concepts: STFT, Phase Vocoder, FFT/IFFT, Windowing, Overlap-Add Method
- Audio Processing: Pitch Detection, Spectral Analysis, Harmonic Filtering, Band-Pass Filtering