Sine function fit

Version (2.05 KB) by R P
Optimization of parameters of the sine function to time series


Updated Thu, 11 Apr 2013 20:00:32 +0000

View License


which is the same that
[param]=sine_fit(x,y,[],[],[]) % no fixed_params, automatic initial_params

[param]=sine_fit(x,y,fixed_params) % automatic initial_params
[param]=sine_fit(x,y,[],initial_params) % use it when the estimation is poor

param = [offset, amplitude, phaseshift, frequency]

if fixed_params=[NaN, NaN , NaN , NaN] % or fixed_params=[]
optimization of offset, amplitude, phase shift and frequency (default)

if fixed_params=[NaN, 1 , NaN , 1/(2*pi)]
optimization of offset and phase shift of a sine of amplitude=1 and frequency=1/(2*pi)

if fixed_params=[0, NaN , NaN , NaN]
optimization of amplitude, phase shift and frequency of a sine of offset=0

%% generate data vectors (x and y)
fsine = @(param,timeval) param(1) + param(2) * sin( param(3) + 2*pi*param(4)*timeval );
param=[0 1 0 1/(2*pi)]; % offset, amplitude, phaseshift, frequency
y=fsine(param,timevec) + 0.1*randn(size(x));

%% standard parameter estimation

%% parameter estimation with forced 1.5 fixed amplitude
[estimated_params]=sine_fit(x,y,[NaN 1.5 NaN NaN])

%% parameter estimation without plotting

Cite As

R P (2023). Sine function fit (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: sigm_fit

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes