Sei sulla pagina 1di 25

PROGRAM 1

AIM: Introduction to MATLAB INTRODUCTION: MATLAB is a software package for high-performance numerical computation and visualization. It provides an interactive environment with hundreds of built-in functions for technical computation, graphics, and animation. Best of all, it also provides easy extensibility with its own high-level programming language. The name MATLAB stands for MATrix LABoratory. BASICS OF MATLAB: MATLAB WINDOWS: MATLAB works through three basic windows, which are discussed below. 1. MATLAB desktop: This is where MATLAB puts you when you launch it. The MATLAB by default, consists of the following sub windows. (a) COMMAND WINDOW: This is the main window. It is characterized by the MATLAB command prompt(>>). (b) CURRENT DIRECTORY: This is where all your files from the current directory are listed. (c) WORKSPACE: This sub window lists all variables that you have generated so far and shows their type and size. (d) COMMAND HISTORY: All commands typed on the MATLAB prompt in the command window get recorded, even across multiple sessions in this window.

2. FIGURE WINDOW: The output of all graphics commands typed in the command window are flushed to the graphics or figure window, a separate gray window with white background color. 3. EDITOR WINDOW: This is where you write, edit, create, and save your own programs in files called M-files. You can use any text editor to carry out these tasks. From within MATLAB, the command is typed at the MATLAB prompt following the exclamation character(!).

FILE TYPES: MATLAB can read and write several types of files. However, there are mainly five different types of files for storing data or programs that you are likely to use often: M-FILES: are standard ASCII text files, with a .m extension to the filename. There are two types of these files: script files and function files. All built-in functions in MATLAB are M-files. MAT-FILES: are binary data-files, with a .mat extension to the filename. Mat files are created by MATLAB when you save data with the save command. The data is written in a special format that only MATLAB can read. Mat-files can be loaded into MATLAB with the load command. FIG-FILES: are binary figure files with a .fig extension that can be opened again in MATLAB as figures. Such files are created by saving a figure in this format using the Save or Save As options from the File menu. P-FILES: are compiled M-files with a .p extension that can be executed in MATLAB directory. These files are created with the PCODE command. MEX-FILES: are MATLAB callable Fortran and C programs, with a .mex extension to the filename. COMMANDS USED IN MATLAB: ON-LINE HELP help help topic demo lists topics on which help is available provides help on topic runs the demo program

WORKSPACE INFORMATION clear clear x y z clc clf clears the workspace, all variables are removed clears only variables x, y, and z clears command window, command history is lost clears figure window

DIRECTORY INFORMATION cd dir mkdir changes the current working directory lists contents of the current directory creates a directory

GENERAL INFORMATION computer date ver tells you the computer type you are using tells you the date as a string gives the license and the MATLAB version Information TERMINATION quit exit quits matlab same as quit

OTHERS plot print title xlabel ylabel stem exp(x) log(x) log10(x) sqrt(x) Generates xy plot Prints plot or saves plot to a file Puts text at top of plot Adds text label to x-axis Adds text label to y-axis Creates stem plot Exponential; ex Natural logarithm; ln(x). Common (base 10) logarithm; log(x)= log10(x). Square root; X

APPLICATIONS OF MATLAB Technical Computing Over one million people around the world use MATLAB for technical computing. They rely on MATLAB to help them develop cancer therapies, search for new sources of energy, make our cars safer and more fuel-efficient, and explore outer space. By combining a powerful numeric engine and technical programming environment with interactive exploration and visualization tools, MATLAB has become the language of technical computing. DIGITAL SIGNAL PROCESSING(DSP) Analyze signals, develop algorithms, and design DSP systems: Math Works signal processing products provide extensive tools and algorithm libraries that let you analyze, design, and simulate DSP systems in a fraction of the time it takes with traditional programming languages such as C and C++. COMMUNICATION SYSTMES Design and simulate complex communications systems: Communications systems products from The Math Works work with MATLAB and Simulink to provide an open, extensible design and simulation environment, with links to third party hardware and software co simulation targets for verifying C/C++ and HDL software. IMAGE AND VIDEO PROCESSING Acquire, process, and analyze images and video for algorithm development and system design: Algorithm development is central to image and video processing because each situation is unique, and good solutions require multiple design iterations. Math Works provides a comprehensive environment to gain insight into your image and video data, develop algorithms, and explore implementation tradeoffs.

TEST AND MEASUREMENT Acquire, process, and analyze images and video for algorithm development and system design: Algorithm development is central to image and video processing because each situation is unique, and good solutions require multiple design iterations. Math Works provides a comprehensive environment to gain insight into your image and video data, develop algorithms, and explore implementation tradeoffs. COMPUTATIONAL BIOLOGY Analyze, visualize, and model biological data and systems: Computational biologists use Math Works products to understand and predict biological behavior using data analysis and mathematical modeling.MathWorks products provide a single, integrated environment to support pharmacokinetics (PK),bioinformatics, systems biology, bioimage processing, and biostatistics. CONTROL SYSTMES Math Works tools for control design support each stage of the development process, from plant modeling to deployment through automatic code generation. Their widespread adoption among control engineers around the world comes from the flexibility of the tools to accommodate different types of control problems. If your control problem is unique, you can create a custom tool or algorithm using MATLAB. COMPUTATIONAL FINANCE Develop and deploy efficient and robust financial applications: Financial professionals worldwide use the interactive programming environment and prebuilt computational libraries of MATLAB to develop quantitative applications in a fraction of the time it would take them in C++ or Visual Basic.

PROGRAM 2 AIM: Program to compute basic sequences. PROGRAM: 1. x=log(3)/log(17); x= 0.3878

2. 3*(((sqrt(5)+1)/(sqrt(5)+1)^2)-4) ans = -11.0729

3. (cosh(x))^2-(sinh(x))^2 ans = 1

4. t =1:10 1 2 3 4 5 6 7 8 9 10

x=(t+1)./(t-1) x= Columns 1 through 8 Inf 3.0000 2.0000 Columns 9 through 10 1.6667 1.5000 1.4000 1.3333 1.2857

1.2500 1.2222 plot(x)

y=t.^2./(2.*t+1) y= Columns 1 through 8 0.3333 0.8000 1.2857 1.7778 2.2727 2.7692 3.2667 3.7647 Columns 9 through 10 4.2632 4.7619 plot(y)

z=sin(t.^2)./t.^2 z= Columns 1 through 8 0.8415 -0.1892 0.0458 -0.0180 -0.0053 -0.0275 -0.0195 0.0144 Columns 9 through 10 -0.0078 -0.0051 plot(z)

5. x=linspace(0,2*pi,50) x= Columns 1 through 8 0 0.1282 0.2565 0.3847 0.5129 0.6411 0.7694 0.8976 Columns 9 through 16 1.0258 1.1541 1.2823 1.4105 1.5387 1.6670 1.7952 1.9234 Columns 17 through 24 2.0517 2.1799 2.3081 2.4363 2.5646 2.6928 2.8210 2.9493 Columns 25 through 32 3.0775 3.2057 3.3339 3.4622 3.5904 3.7186 3.8468 3.9751 Columns 33 through 40 4.1033 4.2315 4.3598 4.4880 4.6162 4.7444 4.8727 5.0009 Columns 41 through 48 5.1291 5.2574 5.3856 5.5138 5.6420 5.7703 5.8985 6.0267 Columns 49 through 50 6.1550 6.2832 y=sin(x) y= Columns 1 through 8 0 0.1279 0.2537 0.3753 0.4907 0.5981 0.6957 0.7818

Columns 9 through 16 0.8551 0.9144 0.9587 0.9872 0.9995 0.9954 0.9749 0.9385 Columns 17 through 24 0.8866 0.8202 0.7403 0.6482 0.5455 0.4339 0.3151 0.1912 Columns 25 through 32 0.0641 -0.0641 -0.1912 -0.3151 -0.4339 -0.5455 -0.6482 -0.7403 Columns 33 through 40 -0.8202 -0.8866 -0.9385 -0.9749 -0.9954 -0.9995 -0.9872 -0.9587 Columns 41 through 48 -0.9144 -0.8551 -0.7818 -0.6957 -0.5981 -0.4907 -0.3753 -0.2537 Columns 49 through 50 -0.1279 -0.0000 plot(y) 6. a=[1 2 3; 1 2 3; 1 2 3] b=[1 2 3; 1 2 3; 1 2 3] a= 1 1 1 b= 1 1 1 2 2 2 3 3 3 2 2 2 3 3 3

a^2+b^2 ans = 12 24 36 12 24 36 12 24 36 2*(a^2) ans = 12 24 36 12 24 36 12 24 36

OUTPUT: X=T+1/T-1
3 2.8 2.6 2.4 2.2 2 1.8 1.6 1.4

10

Y=T2/2*T+1

5 4.5 4 3.5 3 2.5 2 1.5 1 0.5 0

10

Z=SIN(T2)/T2

1.2

0.8

0.6

0.4

0.2

-0.2

10

Y=SIN()
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1

10

15

20

25

30

35

40

45

50

PROGRAM 3

AIM: Write a program for generation and plotting of following functions 1. 2. 3. 4. 5. 6. Unit impulse Unit step Unit ramp Sine Cosine Exponential

PROGRAM: t=-3:1:3; x=[zeros(1,3),ones(1,1),zeros(1,3)]; subplot(3,3,1); stem(t,x); xlabel('time'); ylabel('amplitude'); title('impulse function'); subplot(3,3,2); m=-3:1:3; stem(m,m); xlabel('time'); ylabel('amplitude'); title('ramp'); a=input('enter value of a'); t=0:1:a-1; q=ones(1,a); subplot(3,3,3); stem(t,q); xlabel('time'); ylabel('amplitude'); title('unit step function'); n=-pi:0.1:pi; y=sin(n);

subplot(3,3,4); plot(y); xlabel('time'); ylabel('amplitude'); title('sine function'); n=-pi:0.1:2*pi; y=cos(n); subplot(3,3,5); plot(y); xlabel('time'); ylabel('amplitude'); title('cosine function'); b=input('enter the value of b'); h=-3:1:2; r=exp(b*h); subplot(3,3,6); stem(h,r); xlabel('time'); ylabel('amplitude'); title('exponential function');

OUTPUT:
IMPULSE FUNCTION 1
AMPLITUDE AMPLITUDE

RAMP FUNCTION 4
AMPLITUDE

UNIT STEP FUNCTION 1

2 0 -2 -4 -4

0.5

0.5

0 -4

-2

0 2 TIME SINE FUNCTION

0 2 TIME COSINE FUNCTION

-2

3 4 TIME EXPONENTIAL FUNCTION

1
AMPLITUDE AMPLITUDE

1
AMPLITUDE

2 1.5 1 0.5 0 -3

0.5 0 -0.5 -1

0.5 0 -0.5 -1

20

40 TIME

60

80

20

40 60 TIME

80

100

-2

-1 TIME

PROGRAM 4 AIM: Write a program to study linear convolution of two sequences PROGRAM: x=input('enter the first sequence'); y=input('enter the second sequence'); u=length(x); v=length(y); c=u+v-1; z=conv(x,y); disp(z); disp(y); disp(x); subplot(2,2,1); p=0:u-1; stem(p,x); title('first sequence'); xlabel('time'); ylabel('amplitude'); subplot(2,2,2); q=0:v-1; stem(q,y); title('2nd sequence'); xlabel('time'); ylabel('amplitude'); subplot(2,2,3); n=0:1:c-1; stem(n,z); title('output sequence');

INPUT:

enter the first sequence[1 2 3] enter the second sequence[3 2 1] 3 3 1 8 14 2 2 1 3 8 3

OUTPUT:

FIRST SEQUENCE 3
AMPLITUDE AMPLITUDE

SECOND SEQUENCE 3

1 1.5 TIME OUTPUT SEQUENCE

0.5

0.5

1 TIME

1.5

15

10

PROGRAM 5 AIM: Write a program to design butterworth low pass filter PROGRAM: rp=input('enter the value of passband ripple'); rs=input('enter the value of stopband ripple'); wp=input('enter the value of passband frequency'); ws=input('enter the value of stopband frequency'); fs=input('enter sampling frequency'); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); [b,a]= butter(n,wn,'low'); w=0:0.1:pi; [h,on]=freqz(b,a,w); an=angle(h); m=20*log10(abs(h)); subplot(2,2,1); plot(on/pi,m); xlabel('normalized frequency'); ylabel('gain in decibel'); subplot(2,2,2); plot(on/pi,an); xlabel('normalized frequency'); ylabel('phase in radians');

INPUT: enter the value of passband ripple 40 enter the value of stopband ripple 60 enter the value of passband frequency 0.1 enter the value of stopband frequency 0.3 enter sampling frequency 40 OUTPUT:
0
phase in radians gain in decibel

2 1.5 1 0.5 0

-100

-200

-300

0.5 normalized frequency

0.5 normailzed angle

PROGRAM 6 AIM: Write a program to design butterworth high pass filter

PROGRAM: rp=input('enter the value of passband ripple'); rs=input('enter the value of stopband ripple'); wp=input('enter the value of passband frequency'); ws=input('enter the value of stopband frequency'); fs=input('enter sampling frequency'); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); [b,a]= butter(n,wn,'high'); w=0:0.1:pi; [h,on]=freqz(b,a,w); an=angle(h); m=20*log10(abs(h)); subplot(2,2,1); plot(on/pi,m); xlabel('normalized frequency'); ylabel('gain in decibel'); subplot(2,2,2); plot(on/pi,an); xlabel('normalized frequency'); ylabel('phase in radians');

INPUT: enter the value of passband ripple 3 enter the value of stopband ripple 60 enter the value of passband frequency 0.1 enter the value of stopband frequency 0.3 enter sampling frequency 40 OUTPUT:
50 0 -50 -100 -150
phase in radians gain in decibel

2 1.5 1 0.5 0

0.5 normalized frequency

0.5 normailzed angle

PROGRAM 7 AIM: Write a program to design butterworth bandpass filter PROGRAM: rp=input('enter the passband ripples'); rs=input('enter the stopband ripples'); wp=input('enter the passband frequency'); ws=input('enter the stopband frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs; w2=2*ws/fs; [n]=buttord(w1,w2,rp,rs); wn=[w1,w2]; [b,a]=butter(n,wn,'bandpass'); w=0:0.1:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); xlabel('normalized frequency'); ylabel('gain in decibel'); subplot(2,2,2); plot(om/pi,an); ylabel('phase in radians'); xlabel('normailzed angle');

INPUT:

enter the passband ripples0.34 enter the stopband ripples30 enter the passband frequency1000 enter the stopband frequency1500 enter the sampling frequency10000

OUTPUT:

200 0 -200 -400 -600


phase in radians gain in decibel

4 2 0 -2 -4

0.5 normalized frequency

0.5 normailzed angle

PROGRAM 8 AIM: Write a program to design butterworth bandstop filter PROGRAM: rp=input('enter the passband ripples'); rs=input('enter the stopband ripples'); wp=input('enter the passband frequency'); ws=input('enter the stopband frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs; w2=2*ws/fs; [n]=buttord(w1,w2,rp,rs); wn=[w1,w2]; [b,a]=butter(n,wn,'stop'); w=0:0.1:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); xlabel('normalized frequency'); ylabel('gain in decibel'); subplot(2,2,2); plot(om/pi,an); ylabel('phase in radians'); xlabel('normailzed angle');

INPUT:

enter the passband ripples0.39 enter the stopband ripples39 enter the passband frequency1000 enter the stopband frequency1500 enter the sampling frequency10000

OUTPUT:

20 0 -20 -40 -60


phase in radians gain in decibel

4 2 0 -2 -4

0.5 normalized frequency

0.5 normailzed angle

Potrebbero piacerti anche