Programming assignment 1 - MP3 encoder - Spectrum estimation: Instructions Help Center
The MP3 psychoacoustic model operates on the magnitude spectrum of the input signal. As a first step, therefore, this programmig assignment will ask you to write a function that computes the spectral magnitude in dBs of a chunk of audio data.
Start by downloading the assignment file here and place it in the assignments folder (please review the general instructions page if this confuses you). This is the only file you should modify to perform this assignment.
The function you must write will have the following interface:
Input :
x : a 512-point audio data buffer
Output :
X : a 257-point array of spectral magnitude values in dBs, normalized to 96dB
The function should perform the following steps:
- Window the input signal by a Hanning window, i.e. compute
y[n]=x[n]w[n] wherex[n] is a Hanning window defined asw[n]=c2(1−cos2πnN−1) N is the length of the window (512 in our case) andc is a constant such that∑nw[n]2=511 - Compute the Fourier transform of the windowed input. To do so, use the appropriate FFT function from numpy
- Normalize the FFT output by the size of input (i.e. divide by 512)
- Since the input data is real-valued, we need only half of the magnitude spectrum, so just keep the first 257 values and take the magnitude
- Convert the magnitude to dBs,
|X[k]|dB=20log10|X[k]| ; to avoid numerical warnings, if the original magnitude is zero, set the value in dBs to -100dB - Rescale the output so that the maximum value is 96dB. Remember that rescaling in a log scale is a simple addition!