a complete introduction on matlab and matlab's projects

48
1 CHAPTER-1 1.0 INTRODUCTION OF MATLAB MATLAB is a software package for high performance numerical computation and visualization. It provides an interactive environment with hundred of built in function for technical computation, graphics and animation. The name MATLAB stands for matrix laboratory. MATLAB built in function provide excellence tools for linear algebra, computations, data analysis, signal processing, optimization, numerical solution of ordinary differential equation and many other scientific computation. For those who cannot do without their FORTRAN or C codes. MATLAB even provides an external interface to run those programs from within MATLAB. In MATLAB there are several optional tool boxes available from the developers of MATLAB. These toolboxes are:- 1. Aerospace toolbox 2. Bioinformatics toolbox 3. Communications toolbox 4. Curve system toolbox 5. Curve fitting toolbox 6. Database toolbox 7. Financial toolbox etc. The basic building block of MATLAB is a matrix. The fundamental data type is the array, vectors, scalars, real matrices and complex matrices are all automatically handled as special cases of the basic data type.

Upload: mukesh-kumar

Post on 20-Jan-2017

42 views

Category:

Education


7 download

TRANSCRIPT

Page 1: A complete introduction on matlab and matlab's projects

1

CHAPTER-1

1.0 INTRODUCTION OF MATLAB

MATLAB is a software package for high performance numerical computation and

visualization. It provides an interactive environment with hundred of built in function for

technical computation, graphics and animation. The name MATLAB stands for matrix

laboratory. MATLAB built in function provide excellence tools for linear algebra,

computations, data analysis, signal processing, optimization, numerical solution of ordinary

differential equation and many other scientific computation. For those who cannot do without

their FORTRAN or C codes. MATLAB even provides an external interface to run those

programs from within MATLAB. In MATLAB there are several optional tool boxes available

from the developers of MATLAB.

These toolboxes are:-

1. Aerospace toolbox

2. Bioinformatics toolbox

3. Communications toolbox

4. Curve system toolbox

5. Curve fitting toolbox

6. Database toolbox

7. Financial toolbox etc.

The basic building block of MATLAB is a matrix. The fundamental data type is the array,

vectors, scalars, real matrices and complex matrices are all automatically handled as special

cases of the basic data type.

Page 2: A complete introduction on matlab and matlab's projects

2

1.1 MATLAB WINDOWS

MATLAB works through three basic windows, which are

1. Command window

2. Editor window

3. Figure window

The MATLAB desktop by default consists of the following sub-windows.

1. Command window

2. Workspace window

3. Command history

4. Current directory

Fig 1 The graphical interface to the MATLAB workspace

Page 3: A complete introduction on matlab and matlab's projects

3

1. Command window- This is the main window characterized by command prompt or the

MATLAB command (>>). All the commands including those for running used

programmes are typed in this window at the MATLAB prompt.

2. Editor window- This is where you write, edit, create and save your own programs in

files called M-files.

3. Figure window- The output of all graphics command typed in the command window

are flushed to the graphics or figures window a separate gray colour window with white

background colour.

1.2 FILE TYPES

MATLAB can read and write several types of files. The mainly used are

1. M files

2. MAT files

3. FIG files

4. P files

5. MEX files

1.3 COMMANDS

1. Help- It lists the topics on which help is available.

2. Help win- open the interactive help window.

3. Help topic- It provides the help on topic.

4. Look for string- It lists help topic containing strings.

5. Demo- It runs the demo program.

6. Who- It lists the variables currently in the workspace.

7. Whos- It lists the variable currently work in the workspace.

8. What- It lists the M, MAT & MEX files on the desk.

9. Clear- It clears the workspace.

10. Clear all- It clears all variables & function from workspace.

11. CLC- It clears command window.

12. Home- same as CLC.

13. CLF- It clears the figure window.

14. Path- It gets or sets MATLAB search path.

Page 4: A complete introduction on matlab and matlab's projects

4

15. Copy file- It copies the file.

16. Edit path- It modifies MATLAB search path.

17. VER- It gives the license and MATLAB version information.

18. Quit- Exit MATLAB.

1.4 ENTERING MATRIX

The best way for you to get started with MATLAB is to learn how to handle matrices.

You can enter matrices into MATLAB in several different ways.

Enter an explicit list of elements

Load matrices from external data files

Generate matrices using built-in functions

Creatematrices with your own functions in M-files.

Start by entering as a list of its element.

Separate the element of a row with blanks or commas.

Use a semicolon, ; , to indicate the end of each row.

Surround the entire list of element with square bracket [ ].

For example,

>> A= [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

A= 16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

>>sum(A)

Ans= 34 34 34 34

1.5 Transpose of matrix A

Page 5: A complete introduction on matlab and matlab's projects

5

MATLAB has two transpose operators. The apostrophe operators (eg.A’ ) performs a complex

conjugate transposition. It flips a matrix about its main diagonal and also changes the sig of the

imaginary component of any complex elements of the matrix. The dot-apostrophe operator

(A.’) transpose without affecting the sign of complex elements.

For example,

>> A’

Ans= 16 5 9 4

3 10 6 15

2 11 7 14

13 8 12 1

1.6 Sum of transpose of matrix A

>>sum(A’)

Ans= 34

34

34

34

1.7 Diagonal of matrix A

>>diag(A)

Ans= 16

10

7

1

Page 6: A complete introduction on matlab and matlab's projects

6

1.8 Sum of diagonal of matrix A

>>sum(diag(A))

Ans= 34

1.9 Operation of two matrices

>> A= [4 2 5; 6 4 8; 8 7 5]

A= 4 2 5

6 4 8

8 7 5

>> B= [1 5 4; 2 5 6; 8 5 4]

B= 1 5 4

2 5 6

8 5 4

1.10 Multiply of matrix A and matrix B

>>result=(A*B)

Ans= 48 55 48

78 90 80

62 100 94

1.11 Divison of matrix

>>result=(A/B)

Result= -1.5714 1.7 0.27

Page 7: A complete introduction on matlab and matlab's projects

7

-2 2 0.4

0.7 -0.3 0.9

1.12 Fliplr of matrix A

It flips a matrix from left to right.

>>fliplr(A)

Ans= 5 2 4

8 4 6

5 7 8

1.13 Colon operator

The colon, : , is one of the most important MATLAB operators. It occurs in several different

forms.

For example,

>> A (1:3,2)

Ans= 5

8

8

>>sum(A(1:2,2)

Ans= 13

1.14 Magic of matrix

MATLAB actually has a built in function that creates magic squares of almost any size.

For example,

>>magic(2)

Ans= 1 3 4 2

Page 8: A complete introduction on matlab and matlab's projects

8

1.15 Plotting a graph

The plot function has different forms depending on the input arguments. If y is a vectors, plot

(y) produces a piecewise linear graph of the elements of y versus the index of the elements of y.

if you specify two vectors as arguments, plot (x,y) produces a graph of y versus x.

For example,

These statements use the colon operator to create a vector of x values ranging from 0 to 2π.

Computer the size of thers values and plot the result.

>>X= 0:pi/100:2*pi;

>>Y=sin(x);

>>Plot (x,y)

Now label the axes and add a title. The characters \pi create the symbol π.

>>xlabel (‘x=0:2\pi’)

>>ylabel (‘sin of x’)

>>title (‘plot of the sin function’, ‘font size’, 12)

Page 9: A complete introduction on matlab and matlab's projects

9

Fig 2 sine function graph

1.16 Plotting Data Points with No Line

If you specify a marker, but not a line style, only the markers are plotted. For example:

plot(x,y,'d')

1.17 Line Style Specifiers

You indicate the line styles, marker types, and colors you want to display using string

specifiers, detailed in the following tables:

Page 10: A complete introduction on matlab and matlab's projects

10

Fig 3 Line style specifiers

1.18 Marker specifies

Fig 4 Marker specifiers

1.19 Color specification

Fig 5 Color specification

1.20 Using matlab as a calculator

As an example of a simple interactive calculation just type the expression you want to evaluate

let’s suppose we want to calculate the expression, 1 + 2 × 3. We type it at the prompt command

(>>) as follows,

>> 1+2*3

ans =7

Page 11: A complete introduction on matlab and matlab's projects

11

MATLAB uses a default variable ans, short for answer, to store the results of the current

calculation. Note that the variable ans is created (or overwritten, if it is already existed). To

avoid this, we may assign a value to a variable or output argument name. For example,

>> x = 1+2*3

X=7

will result in x being given the value 1 + 2 × 3 = 7. This variable name can always be used to

refer to the results of the previous computations. Therefore, computing 4x will result in

>> 4*x ans=28.0000

1.21 Creating MATLAB variables

MATLAB variables are created with an assignment statement. The syntax of variable as-

signment is

variable name = a value (or an expression)

For example,

>> x = expression

where expression is a combination of numerical values, mathematical operators, variables, and

function calls. On other words, expression can involve:

• manual entry

• built-in functions

• user-defined functions

1.21.1 Overwriting variable

Once a variable has been created, it can be reassigned. In addition, if you do not wish to see

the intermediate results, you can suppress the numerical output by putting a semicolon (;) at the

Page 12: A complete introduction on matlab and matlab's projects

12

end of the line. Then the sequence of commands looks like this:

>> t = 5;

>> t = t+1

1.22 Error messages

If we enter an expression incorrectly, MATLAB will return an error message. For example, in

the following, we left out the multiplication sign, *, in the following expression.

>> x = 10;

>> 5x

??? 5x

|

Error: Unexpected MATLAB expression

1.23 Making corrections

To make corrections, we can, of course retype the expressions. But if the expression is

lengthy, we make more mistakes by typing a second time. A previously typed command

can be recalled with the up-arrow key ". When the command is displayed at the command

prompt, it can be modied if needed and executed.

1.24 Controlling the hierarchy of operations or precedence

Let's consider the previous arithmetic operation, but now we will include parentheses. For

example, 1 + 2 * 3 will become (1 + 2) * 3

>> (1+2)*3 ans =9

and, from previous example

>> 1+2*3

Page 13: A complete introduction on matlab and matlab's projects

13

ans =7

By adding parentheses, these two expressions give different results: 9 and 7. The order in

which MATLAB performs arithmetic operations is exactly that taught in high school algebra

courses. Exponentiations are done first, followed by multiplications and divisions, and finally

by additions and subtractions. However, the standard order of precedence of arithmetic

operations can be changed by inserting parentheses. For example, the result of 1+2×3 is quite

different than the similar expression with parentheses (1+2)×3. The results are 7 and 9

respectively. Parentheses can always be used to overrule priority, and their use is

recommended in some complex expressions to avoid ambiguity.

Therefore, to make the evaluation of expressions unambiguous, MATLAB has estab- lished a

series of rules. The order in which the arithmetic operations are evaluated is given in Table 1.2.

MATLAB arithmetic operators obey the same precedence rules as those

Precedence Mathematical operations

First The contents of all parentheses are evaluated first, starting

from the innermost parentheses and working outward.

Second All exponentials are evaluated, working from left to right

Third All multiplications and divisions are evaluated, working

from left to right

Fourth All additions and subtractions are evaluated, starting

from left to right

most computer programs. For operators of equal precedence, evaluation is from left to right. Now,

consider another example:

In MATLAB, it becomes

½+32+4/5*6/7

>> 1/(2+3^2)+4/5*6/7

ans= 0.7766

Page 14: A complete introduction on matlab and matlab's projects

14

or, if parentheses are missing,

>> 1/2+3^2+4/5*6/7

Ans=10.18

So here what we get: two different results. Therefore, we want to emphasize the importance of

precedence rule in order to avoid ambiguity.

1.25 Controlling the appearance of floating point number

MATLAB by default displays only 4 decimals in the result of the calculations for example

163.6667, as shown in above examples. However, MATLAB does numerical calculations in

double precision, which is 15 digits. The command format controls how the results of

computations are displayed. Here are some examples of the different formats together with the

resulting outputs.

>> format short

>> x=-163.6667

If we want to see all 15 digits, we use the command format long

>> format long

>> x= -1.636666666666667e+002

To return to the standard format, enter format short, or simply format.

There are several other formats. For more details, see the MATLAB documentation, or type

help format.

Note - Up to now, we have let MATLAB repeat everything that we enter at the prompt (>>).

Sometimes this is not quite useful, in particular when the output is pages en length. To prevent

MATLAB from echoing what we type, simply enter a semicolon (;) at the end of the

command. For example,

>> x=-163.6667;

and then ask about the value of x by typing,

>> x, X=163.6667

Page 15: A complete introduction on matlab and matlab's projects

15

1.26 Managining the workspace

The contents of the workspace persist between the executions of separate commands. There-

fore, it is possible for the results of one problem to have an effect on the next one. To avoid this

possibility, it is a good idea to issue a clear command at the start of each new independent

calculation.

>> clear

The command clear or clear all removes all variables from the workspace. This frees up system

memory. In order to display a list of the variables currently in the memory, type

>> who

while, whos will give more details which include size, space allocation, and class of the

variables.

1.27 Keeping track of your work session

It is possible to keep track of everything done during a MATLAB session with the diary

command.

>> diary

or give a name to a created

>> diary FileName

where FileName could be any arbitrary name you choose.

The function diary is useful if you want to save a complete MATLAB session. They save all

input and output as they appear in the MATLAB window. When you want to stop the

recording, enter diary off. If you want to start recording again, enter diary on. The that is

created is a simple text ¯le. It can be opened by an editor or a word processing program and

edited to remove extraneous material, or to add your comments. You can use the function type

to view the diary or you can edit in a text editor or print. This command is useful, for example

in the process of preparing a homework or lab submission.

1.28 Entering multiple statements perline

It is possible to enter multiple statements per line. Use commas (,) or semicolons (;) to

enter more than one statement at once. Commas (,) allow multiple statements per line

without suppressing output.

Page 16: A complete introduction on matlab and matlab's projects

16

>> a=7; b=cos(a), c=cosh(a)

b =

0.6570

c =

548.3170

1.30

1.29 Mathematical function

MATLAB offers many predefined mathematical functions for technical computing which

contains a large set of mathematical functions. Typing help elfun and help specfun calls up full

lists of elementary and special functions respectively. There is a long list of mathematical

functions that are built into MATLAB. These functions are called built-ins. Many standard

mathematical functions, such as sin(x), cos(x), tan(x), ex, ln(x), are evaluated by the functions

sin, cos, tan, exp, and log respectively in matlab.

Fig6Mathematical function

Fig 7 mathematical formula

Example

cos(x) Cosine abs(x) Absolute value

sin(x) Sine sign(x) Signum function

tan(x) Tangent max(x) Maximum value

acos(x) Arc cosine min(x) Minimum value

asin(x)

atan(x)

exp(x)

Arc sine

Arc

tangent

Exponentia

l

ceil(x)

floor(x)

round(x

)

Round towards +∞

Round towards −∞

Round to nearest

integer

sqrt(x) Square

root

rem(x) Remainder after division

log(x) Natural logarithm angle(x) Phase angle log10(x) Common logarithm conj(x) Complex conjugate

Pi =The π number ,π=3.14159

i,j=The imaginary unit,i= -1

inf= the infinity,∞

NaN=not a number

Page 17: A complete introduction on matlab and matlab's projects

17

We illustrate here some typical examples which related to the elementary functions previously

defined.

As a first example, the value of the expression y = e−a sin(x) + 10y for a = 5, x = 2, and

y = 8 is computed by

>> a = 5; x = 2; y = 8;

>>y=exp(-a)*sin(x)+10*sqrt(y)

y =28.2904

The subsequent examples are

>> log(142) ans=4.9558

>> log10(142)

ans=2.1523

Note the difference between the natural logarithm log(x) and the decimal logarithm (base

10) log10(x).

To calculate sin(π/4) and e10, we enter the following commands in MATLAB,

>> sin(pi/4) ans=0.7071

>> exp(10) ans=2.2026e+004

1.30 Basic plotting

MATLAB has an excellent set of graphic tools. Plotting a given data set or the results of

computation is possible with very few commands. You are highly encouraged to plot

mathematical functions and results of analysis as often as possible. Trying to understand

mathematical equations with graphics is an enjoyable and very efficient way of learning

mathematics. Being able to plot mathematical functions and data freely is the most important

step, and this section is written to assist you to do just that.

1.30.1 Creating simple plot

Page 18: A complete introduction on matlab and matlab's projects

18

The basic MATLAB graphing procedure, for example in 2D, is to take a vector of x-

coordinates, x = (x1, . . . , xN ), and a vector of y-coordinates, y = (y1, . . . , yN ), locate the

points (xi, yi), with i = 1, 2, . . . , n and then join them by straight lines. You need to prepare x and

y in an identical array form; namely, x and y are both row arrays or column arrays of the same

length.

The MATLAB command to plot a graph is plot(x,y). The vectors x = (1, 2, 3, 4, 5, 6) and

y = (3, −1, 2, 4, 5, 1) produce the picture shown in Figure>> x = [1 2 3 4 5 6];

>> y = [3 -1 2 4 5 1];

>> plot(x,y)

Note: The plot functions has different forms depending on the input arguments. If y is a

vector plot(y)produces a piecewise linear graph of the elements of y versus the index of the

elements of y. If we specify two vectors, as mentioned above, plot(x,y) produces a graph of

y versus x.

For example, to plot the function sin (x) on the interval [0, 2π], we first create a vector of x

values ranging from 0 to 2π, then compute the sine of these values, and finally plot the result

Fig 8 plot of vector x and y

>> x = 0:pi/100:2*pi;

>> y = sin(x);

Page 19: A complete introduction on matlab and matlab's projects

19

>> plot(x,y)

Notes:

0:pi/100:2*pi yields a vector that

– starts at 0,

– takes steps (0r increment) of π/100,

– stops when 2π is reached.

• If you omit the increment, MATLAB automatically increments by 1.

1.30.2 Adding titles, axis labels, and annotations

MATLAB enables you to add axis labels and titles. For example, using the graph from the

previous example, add an x- and y-axis labels. Now label the axes and add a title. The character

\pi creates the symbol π. An example of 2D plot is shown in Figure.

>> xlabel(’x = 0:2\pi’)

>> ylabel(’Sine of x’)

>> title(’Plot of the Sine function’)

Page 20: A complete introduction on matlab and matlab's projects

20

Fig 9 plot of sine function

1.30.3 Multiple data sets in one plot

Multiple (x, y) pairs arguments create multiple graphs with a single call to plot. For

example, these statements plot three related functions of x: y1 = 2 cos(x), y2 =

cos(x), and y3 =0.5 ∗ cos(x), in the interval 0 ≤ x ≤ 2π.

>> x = 0:pi/100:2*pi;

>> y1 = 2*cos(x);

>> y2 = cos(x);

>> y3 = 0.5*cos(x);

>> plot(x,y1,’--’,x,y2,’-’,x,y3,’:’)

Page 21: A complete introduction on matlab and matlab's projects

21

>> xlabel(’0 \leq x \leq 2\pi’)

>> ylabel(’Cosine functions’)

>> legend(’2*cos(x)’,’cos(x)’,’0.5*cos(x)’)

>> title('Typical example of multiple plots')

>> axis([0 2*pi -3 3])

The result of multiple data sets in one graph plot is

Fig 10 Multiple data plot

1.31 Specifying line styles and colors

It is possible to specify line styles, colors, and markers (e.g., circles, plus signs, . . . ) using the

plot command.

plot(x,y,’style_color_marker’)

where style_color_marker is a triplet of values. To find additional information, type help

plot or doc plot.

Page 22: A complete introduction on matlab and matlab's projects

22

Fig 11 Attributes for plot

1.32 Array operation and linear equation

1.32.1 Array operation

MATLAB has two different types of arithmetic operations: matrix arithmetic operations

and array arithmetic operations.

1.32.2 Matrix arithmetic operation

As we mentioned earlier, MATLAB allows arithmetic operations: +, −, ∗, and ˆ to be carried

out on matrices. Thus,

A+B or B+A is valid if A and B are of the same size

A*B is valid if A’s number of column equals B’s number of rows

A^2 is valid if A is square and equals A*A

α*A or A*α multiplies each element of A by α

1.32.3 Array arithmetics operation

On the other hand, array arithmetic operations or array operations for short, are done element-

by-element. The period character, ., distinguishes the array operations from the matrix

operations. However, since the matrix and array operations are the same for addition (+) and

subtraction (¡), the character pairs (:+) and (:¡) are not used. The list of array operators is

shown below in Table 3.2. If A and B are two matrices of the same size with elements A = [aij

] and B = [bij ], then the command.

Page 23: A complete introduction on matlab and matlab's projects

23

Fig 12 Array operators

>> C = A.*B

produces another matrix C of the same size with elements cij = aijbij . For example, using

the same 3X 3 matrices,

>> C = A.*B

C =

10 40 90

160 250 360

490 640 810

To raise a scalar to a power, we use for example the command 10^2. If we want the operation

to be applied to each element of a matrix, we use .^2. For example, if we want to produce a

new matrix whose elements are the square of the elements of the matrix A, we enter

>> A.^2

ans =

1 4 9

16 25 36

49 64 81

The relations below summarize the above operations. To simplify, let’s consider two vectors U

and V with elements U = [ui] and V = [vj ].

Page 24: A complete introduction on matlab and matlab's projects

24

U. ∗ V produces [u1v1 u2v2 . . .

unvn] U./V produces [u1/v1

u2/v2 . . . un/vn]

U.ˆV produces [uv1 uv2 . . . uvn ]

1 2 n

Fig 13 summary of matrix and array operation

1.33 Solving of linear equation

One of the problems encountered most frequently in scientific computation is the solution of

systems of simultaneous linear equations. With matrix notation, a system of simultaneous linear

equations is written

Ax=b

where there are as many equations as unknown. A is a given square matrix of order n, b is a given

column vector of n components, and x is an unknown column vector of n components. In linear

algebra we learn that the solution to Ax = b can be written as x = A−1b, where A−1 is the

inverse of A. For example, consider the following system of linear equations

The coefficient matrix A is

Page 25: A complete introduction on matlab and matlab's projects

25

With matrix notation, a system of simultaneous linear equations is written

Ax = b

This equation can be solved for x using linear algebra. The result is x = A−1b. There are

typically two ways to solve for x in MATLAB The first one is to use the matrix inverse, inv.

>> A = [1 2 3; 4 5 6; 7 8 0];

>> b = [1; 1; 1];

>> x = inv (A)*b

x =

-1.0000

1.0000

-0.0000

The second one is to use the backslash (n)operator. The numerical algorithm behind this

operator is computationally e±cient. This is a numerically reliable way of solving system of

linear equations by using a well-known process of Gaussian elimination.

>> A = [1 2 3; 4 5 6; 7 8 0];

>> b = [1; 1; 1];

>> x = A\b

x =

-1.0000

1.0000

-0.0000

This problem is at the heart of many problems in scientific computation. Hence it is impor-

tant that we know how to solve this type of problem efficiently.

1.34 Matrix inverse

Lets consider that the same matrix A

Page 26: A complete introduction on matlab and matlab's projects

26

Commands in matlab for inverse matrix

Which similar to

Page 27: A complete introduction on matlab and matlab's projects

27

CHAPTER-2

2. 0 PROJECT WORK

During the Two months software training, I had participated in various small projects, this help

me a lot in gaining and enhancing my knowledge in the MATLAB coading. During this Two

months I have participated in many projects or targets, which I have completed successfully.

The following are those key skills which I have learnt in these Two months.

2.1 Design a calculator in MATLAB

2.1.1 Function used

1. Strcat

2. Str2num

3. Get

4. Set

2.2 Flow chart

Page 28: A complete introduction on matlab and matlab's projects

28

Fig 14 Flow chart

2.3 Algorithm

1. For this we have first made GUI ,added this push button to which will serve as an

input for taking the number through user and arithmetical input such as ( + ,- , *, /, )

2. We have added static text box for displaying input which is given by user and for

showing the result.

3. Here we have used the logic as taking input from user as string it will take as string

from the user through button and it will add this string to string which if already

present in the static text box.

2.4 Coading

n=get(handles.text1,'String');

m=get(handles.pushbutton17,'String');

Page 29: A complete introduction on matlab and matlab's projects

29

set(handles.text1,'string',strcat(n,m))

% Here we adding two string through function strcat

When we press the equal to (=) button the this string which is present in static

text bar will be converted into the number by using

comment%str2numn=str2num(get(handles.text1,'String'));

set(handles.text1,'string',n)

For function like all clear [AC] we have made hole string zero .

set(handles.text1,'string','0')

2.5 Testing

1.This follows bodmos rule if you gave function 2*3

+4 it will give 10

2. This calculator will give the output for division by zero to any no. as inf means infinity Eg

4/0 =inf.

2.6 Output

Page 30: A complete introduction on matlab and matlab's projects

30

Fig 15 Calculator

2.7 Convolution of two system

2.7.1 Function uesd

1. Inline

2. Str2num

3. Get

4. Set

5. Stem

2.8 Flow chart

Page 31: A complete introduction on matlab and matlab's projects

31

Fig 16 Flow chart

2.9 Algorithm

1. For this we have first made GUI figure shown above ,here T1 & T2 button will give

time period for the signals to generate the graph of the signals.

2. Then from the signals two figures will generate to which we have to convolute.

3. These two graph or (signals) undergo the convolution on

pressing convolution.

4. After that we will get the output of the two signals as a convolution or as a result.

5. For that we have shown below the flow diagram and the logic for the following.

6. Stop.

Page 32: A complete introduction on matlab and matlab's projects

32

2.10 Testing

1. Here we are taking two functions’ range from user and we are plotting the

convolution sum graphically.

2. And here also we are not able to take the input function from the user.

3. We are studying how to take the input function from the user.

2.11 Output

Fig 17 Graph of convolution

2.12 Design a AM Receiver

2.12.1 Introduction

A radio communication system is composed of several communications subsystems that give

exterior communications capabilities. A radio communication system comprises a

transmitting conductor in which electrical oscillations or currents are produced and which is

arranged to cause such currents or oscillations to be propagated through the free space

medium from one point to another remote there from and a receiving conductor at such

distant point adapted to be excited by the oscillations or currents propagated from the

transmitter. One desirable feature of radio transmission is that it should be carried without

wires (i.e.,) radiated into space. At audio frequencies, radiation is not practicable because the

Page 33: A complete introduction on matlab and matlab's projects

33

efficiency of radiation is poor. However, efficient radiation of electrical energy is possible at

high frequencies (>20 kHz). For this reason, modulation is always done in communication

systems.

2.13 Modulation

Modulation is a technique for transferring information or message of lower frequency by

riding it on the higher frequency carrier. In other words, the process by which some

characteristic of a higher frequency wave is varied in accordance with the amplitude of a

lower frequency wave. This solves the major problem of antenna size and signal distortion (or

noise) in communication system. There are two types of modulation:

1. AM

2. FM

2.14 AM Receiver

For extracting the message signal back from the carrier wave we demodulate the RF signal. For

AM demodulation we have different methods.

1. Tuned RF Receiver

Page 34: A complete introduction on matlab and matlab's projects

34

Fig 18 circuit diagram of Tuned RF receiver

2. Regenerative Receivers

Fig 19 Regenerative Receiver

3. Super-heterodyne Receivers

Page 35: A complete introduction on matlab and matlab's projects

35

Fig 20 Superheterodyne Receiver

We here concentrate on design of Super heterodyne Receiver.

2.15 Super heterodyne receiver

The concept of heterodyning an incoming signal to convert it to a lower frequency was

developed by Armstrong and others in 1918.Armstrong's original design, shown in Figure,

was intended to allow low frequency radiotelephone receivers to be adapted for use at newer

HF frequencies being used in Europe.

Fig 21 Original Super heterodyne design

2.16 Circuit diagram of Super heterodyne receivers

Page 36: A complete introduction on matlab and matlab's projects

36

Although super heterodyne radio receivers look not very complicated but for practicable

purposes there must be additional circuitry involved in the design. One of them is Automatic

Gain Control (AGC).The AGC circuit keeps the receiver in its linear operating range by

measuring the overall strength of the signal and automatically adjusting the gain of the

receiver to maintain a constant level of output. When the signal is strong, the gain is reduced,

and when weak, the gain is increased, or allowed to reach its normal maximum. For simplicity

of circuit, we will present a circuit without AGC. The complete circuit given below appears to

be complicated, that is why we have decided to explain it systematically.

Fig 22 Circuit diagram Super heterodyne receivers

Page 37: A complete introduction on matlab and matlab's projects

37

2.17 Components

Local oscillator

Mixer stage

Coupling capacitor

Intermediate frequency transformer/filter (IFT)

Audio amplifier stage

2.18 Local oscillator stage

In most of AM receiver local oscillator is designed with the help of a special company known

as oscillator coil. Their core is movable between the coils. The main purpose of having a

movable core is to tune the oscillator at desire band. The top side of LO is colored white in

order todistinghish it from intermediate frequency transformers. They come in metal housing

and there are five pins plus two pins of metal housing.

Fig 23 The pin configuration of LO

2.19 Mixer stage

Multiplying the RF signal from the antenna with the frequency of LO is an essential part of

demodulation. IC NE612 is used here, because it takes very little power from input signal, the

quality of mixing is very good and output signal is very much close to the intermediate

frequency (IF), it has its own voltage regulator as for mixer circuit the supply voltage should be

very constant. And the biggest advantage is that its use is very simple, attach antenna to pin 1 or

2, ground pin no. 3 and 6 volt to pin no.8. Then connect LO between pin 6 and 7, and get IF

frequency out from pin 4 and 5.

Page 38: A complete introduction on matlab and matlab's projects

38

Fig 24 Block Diagram and pin configuration of NE612

2.20 Coupling capacitor

As we know that in super heterodyne design our RF stage and LO should oscillate in such a

way that their difference is always 455 kHz (IF frequency). In order to get simultaneously

tuning of both circuits, we use coupling capacitor. They are just pair of two capacitors

connected parallel to each other. One is for main tuning and other is for fine-tuning. In the

case of FM, there are four capacitors. There block diagram and pin configuration is shown

below.

Fig 25 Diagram of coupling capacitor

Page 39: A complete introduction on matlab and matlab's projects

39

2.21 Intermediate Frequency Transformer/Filter (IFT)

Intermediate frequency filter is made with the help of transformer similar to the LO stage, so it

is called IFT. They too came in metal housing as LO. The only difference is that they also have

a capacitor built in them. The capacitor can be seen in the following figure.

Fig 25 Details and pin description of IF Filter

As you can see it in figure, the IFT is, in fact, a parallel oscillatory circuit with a leg on its

coil. The coil body has a ferrite core (symbolically shown with single upward straight dashed

line) that can be moved (with screwdriver), which allows for the setting of the resonance

frequency of the circuit, in our case 455 kHz. The same body contains another coil, with fewer

quirks in it. Together with the bigger one it comprises the HF transformer that takes the signal

from the oscillatory circuit into the next stage of the receiver. Both the coil and the capacitor

C are placed in the square-shaped metal housing that measure 10x10x11 mm. From the

bottom side of the housing you can see 5 pins emerging from the plastic stopper, that link the

IFT to the PCB, being connected inside the IFT. Besides them, there are also two noses

located on the bottom side, which are to be soldered and connected with the device ground.

Japanese IFT's have the capacitor C placed in the cavity of the plastic stopper, as shown in

figure. The part of the core that can be moved with the screwdriver can be seen through the

eye on the top side of the housing, figure 10-d. This part is colored in order to distinguish the

IFT's between themselves, since there are usually at least 3 of them in an AM receiver. The

colors are white, yellow and black (the coil of the local oscillator is also being placed in such

housing, but is being painted in red, to distinguish it from the IFT).

Fig 26 Intermediate frequency transformer

Page 40: A complete introduction on matlab and matlab's projects

40

2.22 Detector stage

The detector stage is implemented with the easiest method that is with envelop detection. No

description is necessary, only the circuit is given below. Please note that this method is known

asynchronous detection.

Fig 27 Detector circuit

2.23 Audio amplifier stage

In order to get good and loud voice from the speaker it is essential to have an audio frequency

(AF) amplifier or simply audio amplifier. For this purpose well-known audio amplifier IC

LM386 is used. It is low priced and good quality IC. We can get 20 to 200times amplification

from it. Pin 5 gives the output, which in turn is connected with the loudspeaker. The speaker

should be round about 10fi rated to 1W. If speaker is not available just omit the LM386 and place

a headphone just after the detector.

Fig 28 Audio amplifier

Page 41: A complete introduction on matlab and matlab's projects

41

2.24 Implemantation

Super heterodyne Receivers can be implemented in different ways namely

1. Modern Single Conversion Implementations

2. Multiple Conversion Implementations

3. Up Conversion Implementations

4. Designs with Ultra-Low IFs

5. Designs with Image Rejection Mixers

6. Designs with Selective Demodulators

Fig 29 Implementation

2.25 Matlab coading

2.25.1 Coading

Start

Clear

all;

Close all; % Clear memory and close figures, files, etc.

RF section

Fc = [700 750 800]*1e3; % Carrier frequencies (Hz)

Ac = [1.00 1.25 1.50]; % Carrier amplitudes

Page 42: A complete introduction on matlab and matlab's projects

42

Fm = [1 2 3]*1e3; % Modulation frequencies (Hz)

Dm = [0.25 0.25 0.25]; % Modulation depths

Fs = 20*max(Fc); % Sample rate, 20 times the highest RF (Hz)

Ts = 1/Fs; % Sample period (s)

L = 10/min(Fm); % Duration of signal, 10 times the period of

% the lowest modulation frequency t

t= Ts*(0:ceil(L/Ts)-1); % Array of sample times (s)

Sc = diag(Ac)*cos(2*pi*Fc'*t); % Carrier signals. A three row array with

% each row representing a single RF

% carrier.

Sm = 1 + diag(Dm)*cos(2*pi*Fm'*t); % Modulating signals. A three row array

% with each row representing the

% modulation for a single carrier.

Stx = sum(Sm.*Sc, 1); % RF signal. The superposition of three separately

% modulated carriers. This is the type of signal

% that could be expected at the output of the LNA

% (or input to the mixer).

Mixer section

FLO = 300e3; % Local oscillator frequency (Hz)

ALO = 1; % Local oscillator amplitude

SLO = ALO*cos(2*pi*FLO*t); % Local oscillator signal Smix =

Stx.*SLO; % Signal at the output of the mixer

IF filter section

We have generated a continuous time transfer function for a Butterworth band pass

filter and then converted that to its discrete Equivalent.

Page 43: A complete introduction on matlab and matlab's projects

43

[NUM,DEN] = butter (5, [2*pi*430e3 2*pi*470e3],’s’);

Filter coefficients for a 10th order Butterworth band pass centered at 450 MHz

Hd = c2d(tf(NUM, DEN), Ts); % Discrete equivalent derived from previous

continuous time filter coefficients

Sfilt = filter(Hd.num{1}, Hd.den{1}, Smix); % Signal at the output of the IF filter

Envelope detector section

Srect = Sfilt; Srect(Srect<0) = 0; % Half-wave rectified IF signal tau

tau= 0.1e-3; % Filter time constant (s)

a = Ts/tau;

Srect_low = filter (a, [1 a-1], Srect); % Low pass filtering to recover

the modulating signal

Plotting section

the plots display numerical data from somewhere in middle of the arrays so that the transient

responses from the filters have had a chance to ring out. Each figure contains three plots: the RF

signal, the IF filter output, and the demodulated audio signal. The first figure plots a longer

segment of time so the demodulated audio signal can be distinguished. The second figure plots

a much shorter segment of time to show the detail in the RF signal.

figure;

min_index = ceil(length(t)/2);

max_index = min_index + ceil(2/min(Fm)/Ts);

subplot(3,1,1);

plot(t(min_index:max_index), Stx((min_index:max_index)));

xlim([t(min_index) t(max_index)]); xlabel('Time (s)');

Page 44: A complete introduction on matlab and matlab's projects

44

subplot(3,1,2);

plot(t(min_index:max_index), Sfilt((min_index:max_index)));

xlim([t(min_index) t(max_index)]); xlabel('Time (s)');

subplot(3,1,3);

plot(t(min_index:max_index), Srect_low((min_index:max_index)));

xlim([t(min_index) t(max_index)]); xlabel('Time (s)');

figure;

min_index = ceil(length(t)/2);

max_index = min_index + ceil(150/min(Fc)/Ts);

subplot(3,1,1);

plot(t(min_index:max_index), Stx((min_index:max_index)));

xlim([t(min_index) t(max_index)]); xlabel('Time (s)');

subplot(3,1,2);

plot(t(min_index:max_index), Sfilt((min_index:max_index)));

xlim([t(min_index) t(max_index)]); xlabel('Time (s)');

subplot(3,1,3);

plot(t(min_index:max_index), Srect_low((min_index:max_index)));

xlim([t(min_index) t(max_index)]); xlabel('Time (s)');

Page 45: A complete introduction on matlab and matlab's projects

45

2.26 Output

Fig 30 Output modulation

Fig 31 Modulation

Page 46: A complete introduction on matlab and matlab's projects

46

CHAPTER-3

RESULT & DISCUSSION

The Purpose of the Software training is to provide an opportunity to undergraduates to

identity. I observe and practice how Software is applicable in the industry and engineering

also observe management practices and to interact with fellow works.it is easy to work

with sophisticated machines and Technology.

I feel I got maximum out of that experience also I learnt the way of work is an organization

the importance of being punctual the importance of maximum commitance and the

importance of team spirit.

The training program having Two destination was a lot more useful than staying at one

place throughout the whole Two month in my opinion.i have gained lot of knowledge and

experience needed to be successful in a great,as in my opinion engineering is after all a

challenge and not a job.

Page 47: A complete introduction on matlab and matlab's projects

47

CHAPTER-4

CONCLUSION & FUTURE SCOPE

The project has been successfully completed by having established the user friendly interface with

the help of Matlab tool. It consists of calculator, AM Receiver of two signals and other basic

trigonometric plots. At the same time there is some scope for improvement in the future. It can be

possible to make it more users friendly by adding more variety of functions to it. If we are able to

introduce user defined functions then it will give user what he wants, that will be ultimate success

of our attempts.

Page 48: A complete introduction on matlab and matlab's projects

48

REFERENCES

1.The MathWorks Inc. MATLAB 7.0 (R14SP2). The MathWorks Inc., 2005. [2] S. 2.

J. Chapman. MATLAB Programming for Engineers. Thomson, 2004.

3. C. B. Moler. Numerical Computing with MATLAB. Siam, 2004.

4. C. F. Van Loan. Introduction to Scientific Computing. Prentice Hall, 1997.

5. D. J. Higham and N. J. Higham. MATLAB Guide. Siam, second edition edition, 2005. 6. K. R.

Coombes, B. R. Hunt, R. L. Lipsman, J. E. Osborn, and G. J. Stuck. Differential Equations with

MATLAB. John Wiley and Sons, 2000.

7. A. Gilat. MATLAB: An introduction with Applications. John Wiley and Sons, 2004.

8. J. Cooper. A MATLAB Companion for Multivariable Calculus. Academic Press, 2001.

By Mukesh Kumar or Mukesh Prasad

College-Rimt iet,mandi gobindgarh,punjab