How to detect frequency of a sinusoidual signal with s-function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
%%%%%%%%%%%%%%%%%%%
1 commentaire
Réponses (1)
Nirmal Gunaseelan
le 4 Août 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).
0 commentaires
Voir également
Catégories
En savoir plus sur Block and Blockset Authoring dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!