How to detect frequency of a sinusoidual signal with s-function?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件)
Nirmal Gunaseelan
2011 年 8 月 4 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Block and Blockset Authoring についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!