Sparse Signal fitting in MATLAB, for a sinusoidal function with more than 8 terms?

I'm trying to fit some data belong to a sum of sines function (Fourier sparse) in MATLAB, however, the number of terms of sine function in MATLAB is limited,i.e. to $1 \leq n \leq 8$. However, I want more terms in my fit functions, i.e. over $50$ terms. By the way I do not intent to recover the signal using Compressive-sensing sparse recovery methods or Fourier based curve fitting and my goal is not signal estimation.

• Is there anyway to make MATLAB to fit my data to a sum of sine function with over 8 sinusoidal terms?
• Why there is such constraint in MATLAB (is it technically or arbitrary)? - Is there any toolbox to fit sinusoidal function (especially something that is capable of supporting wieghted data)?
f = fit(X,Y, 'sin10')
Error using fittype>iCreateFromLibrary (line 412)

It is o.k up to sin8 or sin9 parameters.

I appreciate any answer.

• Does each additional term have an increase infrequency proportional to the fundamental frequency (such that you are basically finding the Fourier series)? Because then each sine fit should be independent of each other, because these sine functions are orthogonal to each other. – fibonatic Aug 9 '16 at 2:33
• No, actually the frequencies are randomly chosen. I can't employ fourier, because of leakage. – MimSaad Aug 9 '16 at 11:42
• Can you please explain a little bit more why you cannot use the Fourier Transform to analyse a function into a sum of sinusoids, especially when the result might be sparse? What sort of discriminating capability are you going for? What is the shortest distance (in Hz) you expect two frequencies to end up with? Also, can you say a little bit more about the actual problem you are dealing with? – A_A Aug 10 '16 at 10:25
• @A_A , first, the problem with FFT is leakage (to avoid leakage I must know exactly the frequencies to make window length is the most appropriate) , other than leakage, I have a big problem. Some points in my samples have greater priority than other (like 20% of data are more accurate measurements of the signal). Through curve fitting I can easily wight these important data more. – Mimsaad 38 mins ago – MimSaad Aug 10 '16 at 11:39

MATLAB has a curve-fitting toolbox where you pass a function of your choice to the fit function. Hence, the number of terms is totally up to you in this case.

If you do not have a curve-fitting toolbox, you could try to find a free one or write a fit function by yourself (e.g. with fminsearch). However, this is not the fastest algorithm and also you would have to calculate the fitting errors by yourself.