View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Four-Parameter Sinefit

4.8 | 6 ratings Rate this file 14 Downloads (last 30 days) File Size: 5.44 KB File ID: #23214 Version: 1.5
image thumbnail

Four-Parameter Sinefit


Marko Neitola (view profile)


06 Mar 2009 (Updated )

Least squares sinusoid fit. Optimization toolbox not needed. Data can be non-uniformly sampled.

| Watch this File

File Information

Least squares sinusoid fit algorithm described in IEEE Standard for Digitizing Waveform Recorders (IEEE Std 1057): Algorithm for three-parameter and four-parameter least squares fit to sinewave data using matrix operations.

The algorithm is (in most cases) really quick. If the signal frequency is a guess, it has to be close to true frequency value.

For further information, consult IEEE Std 1057 and/or IEEE Std 1241 documentation.

Now also fits complex sinusoids i.e. phasors with noise and offset.


Modulo Time Plot inspired this file.

MATLAB release MATLAB 7.13 (R2011b)
Other requirements None. Should work on older MATLAB versions.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
20 Jun 2016 Chih-Hung Lee

01 Oct 2012 Eric

Eric (view profile)

06 Aug 2012 Marko Neitola

Marko Neitola (view profile)

For clarification:

Using the three-parameter fit disables the iterative frequency search. To enable this, use searchflag = 0.

For instance, if you want function messages (verbose), graphics (plotflag) and no iterative search, use

verbose = 1;
plotflag = 1;
searchflag = 0;


Comment only
06 Aug 2012 Jeroen

Jeroen (view profile)

25 Jun 2012 Chih-Wei

16 Nov 2011 Daniel Wei

This is actually a cosine fit, I think.

Comment only
28 Sep 2010 K E

K E (view profile)

Here is an example with a regular sinusoid, which may be helpful:
t = 0:0.1:1000 ; % Time must be in seconds, not Matlab time
T = 10 ; % Period (s)
f = 1/T ; % Signal frequency (not sampling frequency!)
y = 2*sin(2*pi*t./T) ; % Sinusoid
[params, yest, yres, rmserr] = sinefit(y, t, f, 1, 1, 1) ;

01 Apr 2010 Edwin

Edwin (view profile)

The program worked fine for me it was exactly what I was looking for. I use it for the estimation of the SINAD and subsequent ENOB value. The method tends to shift more signal to the residual when the signal that is used gets longer.

18 Mar 2009 1.1

A minor bugfix in the plotting operation: now ALL samples are included in modulo-time plots.

18 Aug 2010 1.2

A feature update: added a possibility to fit non-iteratively.

26 Aug 2011 1.3

Improved iteration convergence: the accuracy for the initial frequency guess is more relaxed.

08 Sep 2011 1.4

Fixed a bug in input parameter handling (varargin behavior).

29 Jun 2012 1.5

A feature update: fitting extended to complex sinusoids.

Contact us