Let's open up the file that includes most of the functions

that are needed in the sinusoidal analysis,

which is the sineModel.py which is part of the SMS tools package.

In this file, we have several functions that are of use for

the sinusoidal modeling.

For example, this first one is the sinusoidal tracking, then there is

another one which is cleaning sine tracks, that we will talk about.

Then there is one that implements the whole sinusoidal model analysis and

synthesis, but does not include the tracking aspect,

because this is meant to be used In real time.

So it cannot do a tracking and allow some memory in the process.

So we do not recommend to use that unless you want to

develop some real time kind of concept.

So what we're going to be using, and we recommend to use,

is the sinusoidal sineModelAnal function.

That just performs the analysis part and

is able to do sinusoidal tracking, because it allows to have

all the tracks in one place, and then do some post processing of them.

Okay, so in here the input is the whole inputs out x,

the sampling rate, the window, the FFT size,

the hop size, then the threshold for the pic detection.

And then a number of parameters that are important to control

the time-bearing aspects of the sinusoidal tracking.

For example,

one is the maximum number of sine that will be allowed at the same time.

Default is 100, so normally you put quite a lot of them, so

to allow for creating and disappearing sine wave.

And then we control the minimal duration of a track, so default is 0.01, so

the track that they're going to be shorter than this value are going to be deleted.

And then we going to control the allowed deviation

from one frame to the next of a given track.

So in this case, this deviation, which is in Hertz, 20 Hertz,

it means that in the lowest frequency, it allows from one frame to the next,

for a peak to change frequency by 20 Hertz and still be part of the same track.

And then this freqDevSlope is a way to allow for

this deviation to increase as the frequencies are higher.

In higher frequencies, normally, you would like this deviation to get higher.

So we can change that by controlling this slope.

The bigger it is, the bigger the slope, and therefore,

the bigger the change with the higher frequencies will be.

Okay, and then the function, it's not that long.

Of course, it has a lot of the parameters and

the functions that we have already seen.

The core is this while loop that basically,

what it does is, it iterates over the whole sound,

and it performs all the blocks that we talked about.

So it performs the DFT, using the FFT algorithm,

it performs the pic detection, then it performs peak interpolation,