Programming On Matlab-lokesh

  • Uploaded by: lokeshlok
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Programming On Matlab-lokesh as PDF for free.

More details

  • Words: 994
  • Pages: 79
1. Introduction 2. The MATLAB environment 3. MATLAB Basics 4. Branching Statements 5. Loops 6. Plotting graphs 7.Advantages of MATLAB 8. Disadvantages of MATLAB 9. Conclusion 10. Bibliography

Introduction MATLAB (short for MATrix LABoratory)

Much richer than any other technical

programming language.

The MATLAB Environment The MATLAB Desktop

1. The 2. The 3. The 4. The editor/ 5. The 6. The 7. The 8. The  

Command Window Command History Window start button document window, including the Debugger & Array editor figure windows workspace browser help browser path browser

MATLAB basics  Variables  Arrays  Vectors  Matrices

1.Variables and Arrays Initializing Variables in Assignment Statements An assignment statement has general form

var = expression * var = 40i; * var = var/5; * array = [1 2 3 4]; * x = 1; y = 2; * a = [0 1+7]; b = [a(2) 7 a]; There a = [0 8] & b = [8 7 0 8]

---- echoing-----If a semicolon is added at the end of

statement echoing disappears.

 It occurs due to the absence of semicolon in

the end of instruction.

Initializing with Shortcut

Expression colon operator: first : incr : last >> x = 1 : 2 : 10 x= 1 3 5 7 9

Initializing with Built-In-

Function Arrays can be initialized using the Built-InFunctions. For example the function ‘zeros’ can be used to create an all-zero array of any desired size.  If the functions have two arguments then 1st one will be the no. of rows and the 2nd one be the no. of columns. v.a = zeros (2); vi.b = zeros(2,3); vii.c = [1 2; 3 4]; 

2. Scalar and Array operations Arithmetic Operations  Addition a+b  Subtraction a-b  Multiplication a*b  Division a/b  Exponential a^ b Scalar operation  2^((8+2)/5)=2^(10/5)  =2^2  =4

3. Array and Matrix Operations

Array operations may also occur between an array and a scalar. If the operation is performed between an array and scalar, the value of the scalar is applied to every element of the array.  In contrast, Matrix Operations follow the normal rules of linear algebra, such as matrix multiplication. 

Operations Syntax Array Addition b Array Subtraction Array Multiplication b Array Right Division b Array Left Division b Matrix Right Division b Matrix left Division b

a + a - b a .* a ./ a .\ a / a \

The Logic Data type

The logic data type is a special type of data that can have one of only two possible values: true or false. These values are produced by two special functions true or false. They are also produced by MATLAB operators: relational operator and logical operator

1. Relational Operators: The general form of relational operator is: a1 op a2

Operator

Operation

==

>=

equal to not equal to Greater than less than greater than equal

to <=

less than equal to

~= > <

Logical Operator

Logical operators are operators with one or two logical operands that yields a logical results.There are 5 binary logical operators: AND, inclusive OR, and exclusive OR, and one unary operator: NOT. The general form of logic binary operation is l1 op l2 And the general form of unary logic operation is Op l1 Where l1 & l2 are expressions & variables and op is one of the logic operators

Branching Statements and Program Design  The if Construct

The if construct has form: If control_expr_1 Statement 1 Statement 2 .... else if control_expr_2 statement 1 statement 2 ....

else statement 1 statement 2 .... End

 The switch construct

Switch ( switch_expr) Case case_expr_1, Statement 1 Statement 2 ... Case case_expr_2, Statement 2 Otherwise, Statement 2 End

The For Loop for index = expr statement 1 ... end

MATLAB input and output functions Category Function Description Load/Save Workspace load workspace. Save Workspace. File Opening and Closing fopen file. Fclose Binary I/O fread data from file Fwrite data to file. Formatted I/O fscan data from. fprintf data to file. fget l file, discard new line character. fget s file, keep newline character. File Positioning, Status, delete exist existence of a file. ferror status feof file.

Load Save Open Close file. Read binary Write binary Read formatted Write formatted Read line from Read line from Delete file. Check for Inquire I/O error Test for end of

Plotting graphs

15

10

5

0

­5

­10

0

1

2

3

4

5

6

7

8

9

10

plot of y=x.2­10.*x+15

15

10

y

5

0

­5

­10

0

1

2

3

4

5 x

6

7

8

9

10

1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Logarithmic scales Matlab has provided a way to convert the

normal graphical area in to a logarithmic graphical area . semilogx- for getting x axis on logarithmic

scale semilogy – for getting y axis on logarithmic

scale

50 100 150 200 250 300 350 400 450 100

200

300

400

500

600

rd'

Original

Duller

Combined

Program for Frequency Modulation                        

->> %-- 10/1/06 9:38 AM --% % frequency modulation and demodulation %Y= MODULATE(X, Fc, Fs, 'fm', OpT) fc=10000; fs=100000; f1=200;f2=500; t=0:1/fs:((2/f1)-(1/fs)); x1=cos(2*pi*f1*t); x2=cos(2*pi*f1*t)+cos(2*pi*f2*t); kf=2*pi*(fc/fs)*(1/max(max(x1))); kf=kf*(f1/fc); %- MODULATION opt=10*kf; y1=modulate(x1,fc,fs,'fm',opt); subplot(521);plot(x1); title('originalsingle tone messaga, fs=100000' ) subplot(524);plot(y1);title('time domain FM,signal tone,fc=10000,fm=200, dev=10*fm') fx1 = abs(fft(y1,1024)); fx1 =[fx1(514:1024) fx1(1:513)]; f=(-511*fs/1024):(fs/1024):(512*fs/1024); subplot(524);plot(f,fx1);title('freq. description,single tone,dev=10*fm') %demodulation x1_recov=demod(y1,fc,fs,'fm',opt);subplot(523);plot(x1_recov); >> title('time domain recoverd, single tone, dev=10*fm')

ADVANTAGES Ease of use Platform independent Predefined functions Device- independent plotting MATLAB compiler

DISADVANTGES

CONCLUSION MATLAB is so much powerful that it can handle any of the Technical computing. It is easy to use, so any technician can use it in their work It helps a lot in any type of image ,speech and many types of processing.

Bibliography

Related Documents

Programming On Lsd
May 2020 0
Programming
November 2019 39
Programming
November 2019 29

More Documents from ""