Dear Sir,
can you try this?
x=0:.1:2*pi; % Whatever your x data or time
y= cos(2*x)+sin(2*x); % Whatever your y data
[xData, yData] = prepareCurveData( x, y);
S0=1; % you said you know this number
eqn = @(S1,S2,x) S0/2+S1/2*cos(2*x)+S2/2*sin(2*x); % a different format instead of typing the equation in fittype
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.StartPoint = [1 1];%starting guess for S1 and S2
[fitresult, gof] = fit( xData, yData, eqn, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel x
ylabel y
grid on
I hope this helps... I am really not sure it helps you as you have posted this question in the year 2015 but now it is end of 2018. I answered this because this answer is also needed for me! When I searched for an answer to this, it is looking very strange that nobody had answered your query. All the best!
Yours sincerely,
S.Ganesan.