A Sinusoidal Model assumes that not all the magnitude peaks of a spectrum should be modeled by sinusoids, since peaks can also the sidelobes of the analysis window, the result of noisy components or of other transitional effects. A sinusoid in the frequency domain is the transform of the window used in the analysis, scaled by the magnitude of the sinusoid, centered at the frequency of the sinusoid and with the phase of the sinusoid at time 0 in the center of the window (if zero-phase windowing is used).

A sinusoid can be synthesized by generating the transform of the window in the frequency domain and computing its inverse-FFT.

To do this lab you can start from stpt.m that performs spectral peak analysis/synthesis without any consideration of sinusoidal constraints. Convert it to sinemodel.m

1. Write a function to compute the interpolated peak locations, magnitudes and phases from each spectrum and the obtained local maxima. ex: function [iploc, ipmag, ipphase] = peakinterp (mX, pX, ploc)

The three spectral magnitude values needed for the interpolation can be obtained by:

- N2=length(mX);
- lval = mX((ploc-1).*((ploc-1)>0)+((ploc-1)<=0).*1);
- rval= mX((ploc+1).*((ploc+1)<N2)+((ploc+1)>=N2).*N2);
- val = mX(ploc);

- iploc = ploc + .5*(lval - rval) ./(lval - 2*val + rval);
- iploc = (iploc>=2).*iploc + (iploc<2).*1;
- iploc = (iploc>N2-1).*(N2-1) + (iploc<=N2-1).*iploc;

- lphase = pX(floor(iploc));
- rphase= pX(floor(iploc)+1);
- intpfactor = iploc-ploc;
- intpfactor = (intpfactor>0).*intpfactor+(intpfactor<0).*(1+intpfactor);
- diffphase = unwrap(rphase-lphase);
- ipphase = lphase+intpfactor.*diffphase;
- ipmag = val-.25*(lval-rval).*(iploc-ploc);

To generated a sinusoid in the frequency domain we will be using the main-lobe of the transform of the Blackman-Harris 92dB window. Without zero-padding this lobe has 9 bins. We will be using a 4096 table storing a big main-lobe, from which we will obtain the bins needed for any frequency. The function genbh92lobe.m can be used to initialize the table array bh92lobe.

1. Generate sinusoids in the frequency domain by adding main-lobes of the Blackman-Harris 92dB window. You can use the function genspecsines.m. The function is called by genspecsines(iploc,ipmag,ipphase,M,N,bh92lobe) Try this function by itself by cheking the resulting spectrum with different sinusoidal values and zero-padding values.2. To be able to use different analysis windows we have to undo the effect of the Blackman-Harris 92dB window after the ifft is performed and and a simple window with wich we can overlapp-add by 50%. For example you can define a synthesis window like ws = triang(M)./blackmanharris(M) and multiply it by the ouput buffer before adding it to the output array, like: y(pin+1:pin+M) = y(pin+1:pin+M) + x1(1:M).*ws;

3. Create a new function called sinemodel with the same input parameters as the example above called stpt. Use all that code and add the peak interpolation, the sinusoidal synthesis and the synthesis window.

1. Try different types of sounds and different parameters. What parameter combination works best for each sound? Expain it?