File Exchange

image thumbnail

Four-Parameter Sinefit

version 2.0.0.0 (6.58 KB) by Marko Neitola
Least squares sinusoid fit.

2 Downloads

Updated 04 Jan 2019

View License

IEEE Standard for Digitizing Waveform Recorders (IEEE Std 1057): Algorithm for least squares fit to sinewave data using matrix operations:
- three-parameter (known frequency, non-iterative) and
- four-parameter (general use, find frequency iteratively).

Added features:
- Complex sinusoid fit enabled.
- Alternative 4-parameter fit by using the function fminbnd.

Cite As

Marko Neitola (2019). Four-Parameter Sinefit (https://www.mathworks.com/matlabcentral/fileexchange/23214-four-parameter-sinefit), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Andrew Sun

The original code does a cosine fit. If the time vector is t output parameters are [offset, amp, frq, phi], then the estimated results should be offset+amp.*cos(2*pi*frq.*t+phi).

Eric

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;

[params,yest]=sinefit(yin,t,f,verbose,plotflag,searchflag);

Jeroen

Chih-Wei

Daniel Wei

This is actually a cosine fit, I think.

K E

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) ;

Edwin

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.

Updates

2.0.0.0

Improvements and bug-fixes

1.5.0.0

A feature update: fitting extended to complex sinusoids.

1.4.0.0

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

1.3.0.0

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

1.2.0.0

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

1.1.0.0

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

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