フィルターのクリア

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

1 回表示 (過去 30 日間)
Martin CHEN
Martin CHEN 2011 年 8 月 4 日
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 件のコメント
Rick Rosson
Rick Rosson 2011 年 8 月 4 日
Please format your code properly. Thanks.

サインインしてコメントする。

回答 (1 件)

Nirmal Gunaseelan
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).

カテゴリ

Help Center および File ExchangeBlock and Blockset Authoring についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by