sineFit is a function to detect the parameters of a noisy sine curve, even less than one period long.
It requires only x and y values and no additional parameters as input.
It is tested with R2016a and R2020a.
The mean calculation time is on my PC 13 ms with a maximum of 2400 ms.
Syntax:
[SineParams]=sineFit(x,y,optional)
optional: plot graphics if ommited. Do not plot if 0
Input:
x and y values, y = offs + amp * sin(2pi * f * x + phi) + noise
Output:
SineParams(1):offset (offs)
SineParams(2): amplitude (amp)
SineParams(3): frequency (f)
SineParams(4): phaseshift (phi)
SineParams(5): MSE , if negative then SineParams are from FFT
Method:
This is a brief and not exact description of the program flow.
• Estimate the offset by the mean of all y values.
• Build the FFT with heavy zero padding.
• Take the frequency, amplitude and phase of the largest FFT peak.
If the frequency is at the Nyquist limit or the period is less than one, add extra frequencies for evaluation.
• Take those values as initial values for the regressions.
• Take the resulting MSE as rating.
• Exclude results above Nyquist frequency.
• Depending on the number of samples and the MSE, set a limit for an accepted amplitude in relation to the FFT amplitude.
• If the amplitude from regression is higher than the accepted amplitude, take the FFT parameters.
A demonstration GUI is included.
For more information read the "ReadMe.pdf".
Cite As
Peter Seibold (2023). Sine fitting (https://www.mathworks.com/matlabcentral/fileexchange/66793-sine-fitting), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
3.0.2 | Some changes in sineFitDemo in respect to 'run xy.mat' |
||
3.0.1 | Minor changes |
||
3.0.0 | No toolbox required anymore |
||
2.1 | Simplified code, faster processing, improved to work down to 0.1 periods, some more correct detections. |
||
2.0.0.1 | Image changed |
||
2.0.0 | Totally new approach with Fourier transformation results as initial parameters for fitting function. |
||
1.0.0.1 | Description corrected |
||
1.0.0.0 | spelling |