Wednesday, June 17, 2020

Function in matlab

In this article, I am going to discuss the function in Matlab. The function is the set of instructions in any programming language and it performs a particular function. Matlab has different features and we can use Matlab for a different purpose and we can use different tools like image processing, machine learning, deep learning, audio processing, etc. Matlab is such a tool where the different tasks can be performed including the programming. In Matlab the syntax of the function is given below:

function [output1,output2,...]=function_name(input_var1,input_var2, ....)
%code is written here
end

For example:
Let's create a function that adds two numbers with the function name add.
 
function x=add(a,b)
x=a+b;
end

The above function is one output variable and two input variables. x is the output variable and a, and b are input variables.
The function add can be called by the following command:
>>add(5,10)
the output will be:
ans= 15
or,
>>var=add(5,10)
output:
var=15

Similarly, let's create another function with two input variables and two output variables with function name fun2. The function can be defined in Matlab as follows:

function [x,y]=fun2(a,b)
x=a+b;
y=a*b;
end

In the above function, a and b are input variables and x and y are the output variables. The x stores the sum of a and b. y stores product of a and b. The function fun2 can be called using the following command:
>>[out1,out2]=fun2(10,5)

the output will be:
out1=15
out2=50

The function in Matlab can be demonstrated in the following video.


For more articles and video please follow this blog and subscribe my youtube channel:

Sunday, November 25, 2018

Matlab simulink and code for y-bus formation, full wave converter

How to convert any file into pdf and viceversa



https://www.youtube.com/watch?v=tW1PoGZ1mL8&t=2s
https://www.youtube.com/watch?v=tW1PoGZ1mL8&t=2s

DC Circuit breaker using SCR

INTRODUCTION

                  The project deals with the design of the DC circuit breaker using SCR (Silicon Controlled rectifier). A circuit breaker is a tool which breaks the circuit when any fault occurs in the circuit and after normal condition, it brings the circuit in ON condition and the circuit again to conduct. The circuit breaker is the advanced form of the fuse. The circuit is disconnected by fuse when the rated current flows in the circuit and it can’t be changed in ON position after coming in normal position and external agent is required to do it. But the circuit breaker does it itself. The SCR is semi-controlled device and act as switch which can be changed in on position by applying gate pulse but changing it into off position is not in our hand and to do so a technique is required which is called commutation of SCR. In this project we are using complementary-commutation.
There will be two SCR and the cathode terminal of both scr is connected to ground (-ve terminal of source) and one terminal of capacitor is connected to anode of one of the scr and other terminal to that of other scr. The load is connected to source voltage and one of the terminals of capacitor and one resistor is connected to another terminal of the capacitor to bypass the current whenever fault is occurred. The this is done by microcontroller i.e. Arduino. We are designing the DC CB for 20V and 1A rating.
CIRCUIT DIAGRAM

CIRCUIT DESCRIPTION AND PRINCIPLE OF OPERATION
               The basic circuit for DC circuit breaker is shown in the figure A. The SCR 1 is main SCR. When it is necessary to break load current, the SCR 1 is turned off.  There is no control circuit given in this figure for simplification. When the SCR 1 is turned on, the load voltage is equal to supply voltage and charging of the capacitor is done through path (+) Vdc – R1 – (+) C – C (-) – SCR 1 – Vdc (-). The polarity of capacitor charging voltage is shown in the figure A. When it is require breaking load current, the SCR 2 is turned on. As soon as the SCR 2 is turned on, the SCR 1 is turned off due to reverse voltage across it. The capacitor once again charges with reverse polarity through path (+) Vdc– LOAD – (+) C – C (-) – SCR 2 due to turned off the SCR 1. When voltage across capacitor reaches up to supply voltage, the load current becomes zero resulting SCR 2 is turned off. The current passes through load resistance R1 becomes less than the holding current of the SCR 2.
The value of R1, R2 and C can be calculated as follows:
Supply voltage, Vs =20V
Rated current, I = 0.5A
 Vs/I=20/0.5=40 Ohms
Holding current of SCR=20mA, so
R2 = 20/20*10^3=1kOhm
If safety factor=2 and turn of time of SCR = 130us, then
C=130*10^(-6)/(40*ln(2))= 4.7uF

SOURCE CODE
double v = 0;
double c = 0;
void setup(){
Serial.begin(9600);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
for(int i = 0; i < 1000; i++){
v = (v + (0.0048828* analogRead(A0))); // (5 V / 1024 (Analog) = 0.0049) which converter Measured analog input voltage to 5 V Range
delay(100);
}
v = v /1000;
c = (v -2.515)/ 0.1; // Sensed voltage is converter to current
Serial.print("\n Voltage Sensed (V) = ");
Serial.print(v,4);
Serial.print("\t Current (A) = ");
Serial.print(c,4);
if(c>0.13){
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
}
  else{
  digitalWrite(9,HIGH);
  digitalWrite(8,LOW);
  }
  delay(500);
}
OUTPUT

                            
PROTOTYPE MODEL



Saturday, November 10, 2018

Traffic Light controller using 8051 Micro-controller in Assembly language programming


This is the mini project based on the 8051 microcontrollers and simulation of it in Proteus software using the MCU 8051 IDE. You can see the simulation diagram below and the video demonstrate the procedure for the simulation of traffic light controller.


Circuit diagram:

Source code:
ORG 00H
MOV P2,#00H
MOV P3,#00H
MAIN:
     SETB P2.2
     SETB P3.2
     SETB P2.3
     SETB P3.3
     ACALL DELAY1
     SETB P2.4
     SETB P3.4
     CLR P2.3
     CLR P3.3
     ACALL DELAY2
     MOV P2,#00H
     MOV P3,#00H
 
     SETB P2.5
     SETB P3.5
     SETB P2.0
     SETB P3.0
     ACALL DELAY1
     SETB P2.1
     SETB P3.1
     CLR P2.0
     CLR P3.0
     ACALL DELAY2
     MOV P2,#00H
     MOV P3,#00H
     SJMP MAIN
DELAY1: MOV R0,#255D
    H1: MOV R1,#255D
    H2: MOV R2,#71D
    H3: DJNZ R2,H3
        DJNZ R1,H2
        DJNZ R0,H1
    RET
DELAY2: MOV R0,#255D
    H4: MOV R1,#142D
    H5: MOV R2,#51D
    H6: DJNZ R2,H6
        DJNZ R1, H5
        DJNZ R0, H4
    RET
END
youtube