Wednesday, April 29, 2015

How To Update Workspace Variabel By Using Simulink

Anytime, we need to update variabel in Workspace by using simulink, there is some way to do it. you can use To Workspace Block in simulink, there is disadvantage if we use this block. this block will update workspace varible in time array. it will result the array variable in workspace,  so for you who want update workspace only single value, you can not use To Workspace Block.

To Update Workspace variable with Single Value by using simulink. you need  Interpreted MATLAB Function block. and use the following script

assignin(ws, 'var', val)

**you can type doc assignin for explanation about it

for example you want update Kp variable in workspace, then you can type the following script in matlab interpreted function

Kp_value =2;
assignin('base', 'Kp_m', Kp_value );

Tuesday, April 28, 2015

Matlab: How To Plot Data Array to Bode Diagram

There is numorous research that need us to plot Bode Diagram, using the usual way, we can plot bode diagram easily using matlab command bode(sys). where sys is transfer function.
Unfortunately, we didnt know  the transfer function of our system, maybe because of nonlinearity or system is too complex to convert to transfer function.

What we have is only the data, then we can convert the data to bode diagram. Lets see the following example

data=[10   0.0911222683470981   -1.58847081420007
17.1132830416178   0.155513705289354   -1.59826007442724
29.2864456462524   0.265372788697364   -1.61337362876168
50.1187233627272   0.452875507309409   -1.63924925736688
85.7695898590894   0.771380837522393   -1.6844579215245
146.779926762207   1.30422486175599   -1.76177744417405
251.188643150958   2.15885228954428   -1.88922949657677
429.866234708228   3.38909945622017   -2.08389456518048
735.642254459642   4.79331476991719   -2.33778424860481
1258.92541179417   5.90723048305756   -2.59657088827632
2154.43469003188   6.51210885390879   -2.80121801151038
3686.94506451958   6.76551329794937   -2.93773717631133
6309.57344480193   6.85906013908311   -3.02175637289138
10797.7516232771   6.89190068991012   -3.07200435455205
18478.4979742229   6.9032185997441    -3.10201666772075
31622.7766016838   6.90708374137897   -3.12039586346281
54116.9526546464   6.90836924161824   -3.13252146311361
92611.8728128794   6.90870360455884   -3.14196763982071
158489.319246112   6.90851104747202   -3.15152485034634
271227.257933203   6.90754724630841   -3.16401689981387
464158.883361278   6.90459064111762   -3.18312952818843
794328.234724283   6.8959080205459   -3.21447528466877
1359356.39087853   6.87065827244468   -3.26713087846712
2326305.06715363   6.79832956499895   -3.35572740118132
3981071.70553497   6.59941778875662   -3.50204977064032
6812920.69057961   6.10718328006143   -3.73075734041662
11659144.0117983   5.13927320828323   -4.04839453004176
19952623.1496888   3.82351328567971   -4.42101649285181
34145488.738336    2.62807468084941   -4.80832034047117
58434141.3373518   1.83567026586748   -5.20125372342626
99999999.9999999   1.41059927338957   -5.58031981846252]

To Convert To Bode diagram, use the following Matlab script

xlabel('frequency log10(\omega)');ylabel('Gain(dB)');title('Amplitude')
xlabel('frequency log10(\omega)');ylabel('Phase(rd)');title('Phase')


Thursday, April 16, 2015

How Quadrotor Fly ?

UAV is one of the technologies that are currently being favored by many engineering students and researchers , even annually existing UAV competition from the high school level , up to the professional category .

Well one type of UAV is quadcopter , quadcopter has 4 motors actuators , where these four separately controlled by the main controller , usually with atmega microcontroller or are now widely using ready-made modules like ardupilot and multiwii . Well the quadcopter is moving with the motor , where the two motors have different rotational direction with two other motors . the question is how quadcopter flying vertically , laterally and remain in place ? The following animation might explain your question

The next one (bellow) shows how the quadrotor would increase altitude.

Here's how the quadrotor would move along the horizon plane

Finally, this animation shows how the quadrotor would rotate around it's main vertical axes (yaw)

Fuzzy Logic Mamdani Rule Matlab Simulink

Fuzzy Logic is one control method that is widely used by students in completing tasks easily implement it in the end because of a Plant . : D

Fuzzy Logic is an increase of Boolean logic dealing with the concept of partial truth . When classical logic to claim that everything can be expressed in binary terms ( 0 or 1 , black or white , yes or no ) , fuzzy logic replaces Boolean truth with a level of truth . ( Wikipedia ) .

Fuzzy Logic has several stages:
1. Normalization with Delta Gain Error and error
2. fuzzification
3. Fuzzy Inference
4. Defuzifikasi
5. Gain control u

1. Gain Error and Delta Error

Gain error is the gain for error where error = ref - aktual_output
while the gain for the gain changes delta_error error de = e ( k ) - e ( k - 1 )

2. fuzzification
is the process of changing the delta error value and error into crisp value mf , there are several types of fuzzification are:
 - Triangle
 - Gaussian
 - Generalized Bell
 - Sigmoid
 - Z

3. Fuzzy Inference
 Fuzzy inference is a process of formulating the mapping inputs to outputs using fuzzy logic and the rules of If Then. In this task used the rule that one is rulenya

4. defuzzification
It is the process of turning into a crisp control signal values ​​that can be used to control the plant .

5. Gain control u
this is optional , if needed then use this to multiply the output defuzifikasi to fit the plant work .

Matlab Curve Fitting Tutorial

Curve fitting is the process of matching the pattern data in the form of a graph into an equation . The simple notion that changing the graphics data into an equation that can represent the graph. this can be done easily in matlab . follow the following tutorial:

1. Open matlab

2. prepare your chart data . if it does not have as an example here we create a data chart with the following equation .

type in the command windows matlab

x = -10 : 0.1 : 10 ;

y = x ^ .2 + 10 ;

 make sure the workspace window there is a data x and y .

3. type cftool to use matlab curve fitting , then you will see a dialog like the following illustration:

4. then select the x data with ' x ' and y data with ' y ' which we have generated by typing the equation above earlier . then the graph will automatically display the data in graphical form as shown below .

5. from the picture above we can see there are two lines , the color black is the data that we have , and the blue is estimated data with polynomial formula . of the graph we can see there is no match at all . then we find the formula or degree option available on the column polynomial

6. Let's first try to increase the degree of the polynomial into two . As a result as follows :

from the picture above shows the blue line resembles the outline of a black color , so that it can be said of this equation is appropriate to represent the equation y = x ^ .2 + 10 . The new equation we get we can see on the left side of the graph . as follows:

can be seen from the picture above the new equation that represents the graph , ie

y = p1 * x ^ 2 + x + p2 * p3

 with the value of p1 , p2 , p3 as written above , by ignoring the very small value ie p2 . then we will get a new equation above becomes

y = x ^ 2 + 10 .. so the curve fitting equation is able to recognize up to 99 % .

to represent the data above , we do not have to use a polynomial equation , you can also try the exponential or Gaussian degree 2 equation , but the result is less good for the exponential gaussian results are compared with the second degree .

for exponential equations that represent the data is :

f(x) = a*exp(b*x) + c*exp(d*x)
Coefficients (with 95% confidence bounds):
       a =       7.948  (7.274, 8.622)
       b =     -0.2705  (-0.2804, -0.2606)
       c =       7.948  (7.275, 8.622)
       d =      0.2705  (0.2606, 0.2804)

and for gaussian is :

f(x) =  a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)
Coefficients (with 95% confidence bounds):
       a1 =       173.8  (168.3, 179.4)
       b1 =       15.77  (15.5, 16.05)
       c1 =       8.442  (8.306, 8.579)
       a2 =       173.8  (168.3, 179.4)
       b2 =      -15.77  (-16.05, -15.5)
       c2 =       8.442  (8.306, 8.579)

Good luck with your data .

Hopefully this article helps you , :)

How to Create Circle Reference in Matlab

This is a simple problem but the question is how to implement it in a script ? .

Example circle Reference  is as a reference movement of a system , eg UAV aircraft, quadrotor , submarine ( AUV ) , Robot Manipulator and many others . Here are the steps to create circle references . you need to remember the concept of a circle in the XY plane is a circle formed of Sine on one axis and Cosine on another axis.

1. Open matlab simulink
2. Open the Library Browser

3. Select the User -defined Function and select Matlab Function . => add to Untitled

4. the Source , select the clock => add to Untitled

5. the Sink , select Scope => add to Untitled

5. the Sink , select the XY -Graph =>  add to Untitled

6. Double click on matlab function and type following script

function [x,y] = Circle(t)
freq = 0.1;
Gain = 10;
x = sin(freq*t)*Gain;
y = cos(freq*t)*Gain;

 Gain is used to enlarge the radius of the circle , the frequency for the speed trajectory .

6. then connect with the input clock t and scope and XY -Graph with output in matlab function block as shown below :

7. and then Run, so on X-Y Graph will showing the following result:


Saturday, March 21, 2015

Quadrotor Matlab Simulation on Ground Station

I've just made matlab simulation on my GCS. quadrotor control simulation using matlab and for 3D view i used google earth plugin. to comunicate between Matlab to GCS, it use simple UDP protocol. it work well. you can see to my videos at youtube belows :