Borrar filtros
Borrar filtros

How to detect frequency of a sinusoidual signal with s-function?

1 visualización (últimos 30 días)
I want to detect the frequency of grid voltage(outside of an PV inverter) in Matlab. The following is the m-file program, however what i want is to implement it in Simulink with s-function. does anyone can help? how to transfer it to the form of s-function. thank you in advance.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clc;
f1=50.05;
fs=400;
det=1/400;
t=0:det:2-det;
N=length(t);
y1=sin(2*pi*f1*t+pi/3);
a=0;
for i=1:1:N-1
if (y1(i)>0)&&(y1(i+1)<=0)
a=a+1;
if a==1
t1=t(i)+(y1(i)*det)/(y1(i)-y1(i+1));
end
t2=t(i)+(y1(i)*det)/(y1(i)-y1(i+1));
end
end
f=(a-1)/(t2-t1)
e=(f-f1)/f1*100
end
%%%%%%%%%%%%%%%%%%%

Respuestas (1)

Nirmal Gunaseelan
Nirmal Gunaseelan el 4 de Ag. de 2011
Provided you are not interested in generating code from the resulting Simulink model, Level 2 MATLAB-file S-functions would be the way to go. I have not looked at your code (follow instructions in the help page).

Categorías

Más información sobre Block and Blockset Authoring en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by