File Exchange

## Frequency, amplitude, phase and mean value of sine wave

version 1.0 (2.46 KB) by

The function sinfapm evaluates parameters of sampled sine wave

Updated

The function sinfap.m evaluates frequency, amplitude, phase and mean value of a uniformly sampled harmonic signal
x(t) = a.sin(2.pi.f.t + phi) + x_m
It uses a vector version of 3-point formulae derived by application of
Z-transform (see [1]) for finding amplitude and frequency of a signal.
If more than two output parameters are to be determined, all of them are optimized in the least squares sense by the function LMFnlsq.

Calls:
frq = sinfapm(x,fs); % Get only frequaency of sine-wave
[frq,amp] = sinfapm(x,fs); % Get frequency and amplitude
[frq,amp,phi] = sinfapm(x,fs); % Get frequency, amplitude and phase
[frq,amp,phi,ave] = sinfapm(x,fs); % ditto plus mean value
The set of more than two output parameters can be found by calling
[frq,amp,phi] = sinfapm(x,fs,Name_1,Val_1,Name_2,Val_2, ...);
[frq,amp,phi,ave] = sinfapm(x,fs,Name_1,Val_1,Name_2,Val_2, ...);

Input arguments:
x % vector of samples
fs % sampling frequency [Hz]
Name_i % name of the i-th optional parameter for optimization
Val_i % value of the i-th optional parameter (see function LMFnlsq)
Output arguments:
frq % frequency of x [Hz]
amp % amplitude of x
Examples:
[f,a,phi,ave] = sinfapm([1.3633;-.2428;-0.9705;1.8130;-1.9631],10);
% f = 4.0000
% a = 2.0000
% phi = 0.7500
% ave = -2.2806e-005
[f,a,phi] = sinfapm([.707,1,.707,0],20,'Xtol',1e-4);
% f = 2.5001
% a = 0.9999
% phi = 0.7853 % pi/4 = 0.785398...

arul s

### arul s (view profile)

hi all
i am only get my amplitude in precent signal
this function what code or keyword can i use?

Miroslav Balda

### Miroslav Balda (view profile)

The function sinfapm is not maintained any more. Use the function sinide instead, which is much more stable. See

will wehner

### will wehner (view profile)

Thank you.
Unfortunately, I believe there are still problems with the function.

I emailed you an example (miroslav@balda.cz) with estimation of real data. It uses your function and compares to estimation with nlinfit.m

Will

Miroslav Balda

### Miroslav Balda (view profile)

@Will
I am sorry that the function behaved wrong. A reason for it was a hight sensitivity of the function to inaccurate initial guess of the sought parameters. Since it was impossible to improve it by little modification, I decided to build a new function. It will appear in a short time under the name sinide.m.

will wehner

### will wehner (view profile)

t=0:.01:1;
y=2*sin(2*pi*10*t+3)+5;

[f,a,phi,ave] = sinfapm(y,100)

Returns
f=2.486
a=-0.1283
phi=1.5719
ave=5.0035

John

### John (view profile)

When I implement this function for noisy sine vawes, the amplitudes seem to be very far from reality. Often, amplitudes have even minus signs(?). Any ideas why ?

Pablo

### Pablo (view profile)

txs a lot =)).
i need it that mean

david sweeney

How do I get this file to run????

Ramesh Pachar

##### MATLAB Release
MATLAB 7.6 (R2008a)