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!