MATLAB: Peak observer in simulink

control

hi i want to make a peak observer in Simulink. the system i'm working on is aboıut Fuzzy Logic Parametric Adaptive control. I need to observe the maxima after overshoot then regulate the parameters for Integral and Derivative. then again below the reference i need to observe the minimum so regulate those parameters again. Is there any block in simulink that i can observe? another question, can Matlab Functions send and receive data from workspace in real time? Please help me it's important… the last one the code below is that i wrote to sense the peak but it never goes to the loop it supposed to be… this is the matlab fuction in simulink and in every look it supposed to come this function and do the loops. Please help meeeeeeee
diff = abs(1-y); lambda = 1; while (b == 0) lambda = 1; if (a == 1) lambda = 1; if (y < 1) lambda = 1; elseif (y > 1) a = 2; lambda = 1; end break; end if (a == 2) =>>>>>>>>> it never reaches these loops after here. lambda = 1; if ((diff-fark)>0) lambda = 1; elseif ((diff – fark)<0) a = 3; lambda = fark; end break; end if (a == 3) lambda = 1; if(y > 1) lambda = 1; elseif (y<1) lambda = 1; if ((diff – fark) > 0) lambda = fark; a = 4; end end break; end if ( a == 4) lambda = 1; if (y < 1) lambda = 1; elseif (y > 1) lambda = 1; if ((diff-fark) < 0) lambda = fark; a = 5; end end break; end b = 1; end l = lambda; a_k2 = k2/l; a_beta = l*beta; a_kontrol1 = 0; a_fark = diff; a_kontrol = a; end
thanks for your help in advance.

Best Answer

the code before i attached here doesn't seem good so i attache the txt file here please help meeeeee