Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with a script in MATLAB (user defined function block)

Status
Not open for further replies.

Eng.Salwa1

Newbie level 4
Joined
Feb 6, 2016
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
71
Hello everyone
I m trying to detect sag,swell and interruption using the user defined function block.
I am able to detect sag ,swell but the only problem i am facing is with the interruption.
As you can see from the figure, the first subplot is a filtered sine wave (Lowpass filter Fn=8) when there is an interruption my script doesnt understand it is an interruption so when filtered sinewave starts to gradually decrease , my sag detector interprets this decline as a sag. How can i modify it so it would only read interruption?
Ts=1e-6

Sag detector script
Code:
function y = fcn(u)

if (u<=293) && (u>=260.5);  
    y=0.5;
elseif (u<260.5) && (u>=228);
    y=1;
    elseif (u<228) && (u>=195.5);
    y=1.5;
    elseif (u<195.5) && (u>=163);
    y=2;
    elseif (u<163) && (u>=130.5);
    y=2.5;
    elseif (u<130.5) && (u>=98);
    y=3;
    elseif (u<98) && (u>=33);
    y=3.5;
else
   y=0; 
end

Interruption detector
Code:
function y = fcn(u)


if abs(u<=0.5);    
    y=1;
else
    y=0;
end

Thank you
https://obrazki.elektroda.pl/6504222800_1458145147.jpg
 
Last edited by a moderator:

Do you really mean abs(u<=0.5) or (abs(u)<=0.5); they are not really the same thing
 

Do you really mean abs(u<=0.5) or (abs(u)<=0.5); they are not really the same thing

you are right (abs(u)<=0.5); but it doesn't make any difference, my sag code needs to be modified. The interruption code is working perfectly.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top