File Exchange

## Four-Parameter Sinefit

version 1.5 (5.44 KB) by

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

4.83333
6 Ratings

Updated

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.

Chih-Hung Lee

Eric

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;

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

Jeroen

Chih-Wei

Daniel Wei

### Daniel Wei (view profile)

This is actually a cosine fit, I think.

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

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.