Lab 7: Harmonic Modeling

A Harmonic Model assumes that not all the magnitude peaks of a spectrum should be modeled by sinusoids because many peaks can be the sidelobes of the analysis window, the result of noisy components or other transitional effects. 

In order to decide if a spectral peak is a harmonic or not we have to perform a detection of the fundamental frequency, f0, of the spectrum and check it the peak is close to an ideal harmonic of the fundamental frequency. 

To do this lab you can start from the sinemodel.m, which requires peakinterp.m, genbh92lobe.m and genspecsines.m, converting it into harmonicmodel.m

7.1: Detection of F0

We will be using the Two-way-mismatch algorithm that is implemented in f0detection.m and that can be called by [f0,f0error,isHarm]=f0detection(mX, fs, iploc, ipmag, ethreshold)

1. Incorporate the
f0detection function into the new harmonicmodel.m code.

2. Generate a square wave (ex: t = 0:1/44100:1; y = square(2*pi*200*t);), perform the harmonic analysis, and plot the f0 and f0error values for the whole duration of the sound. You can improve the detection by narrowing down the f0 range, adding a minf0, maxf0 parameters. Do it also with a real sound that is harmonic. What is the effect of ethreshold in the f0 detection? What other input parameters of the harmonicmodel function affect the f0 detection? How?

7.2: Detection of harmonics

Once the f0 in a given frame is detected we have to find the harmonics present in the frame. We can do it by finding the closest peaks to the harmonic series of f0, and defining a maximum of harmonics to find, using the parameter nSines, ex:
1. Incorporate this code into your function and plot the harmonic values found on top of each spectral frame of the sound. 

2. Complete the function harmonicmodel.m by generating only the harmonics obtained. The function could be called by: y = harmonicmodel(x, fs, w, N, H, t, nSines, minf0, maxf0, f0threshold)

7.3: Testing the harmonic model

Test the algorithm with different harmonic and inharmonic sounds. You will have to change the parameters to get a good result.