SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Lab No.04

MATLAB graphics

Designed by : Dawar Awan
dawar@cecos.edu.pk
CECOS College of Engineering and IT

March – July 2012
Discrete signals
 Plot the discrete signal x = [1 2 3 4] in MATLAB
4

3
2

1

-1

0

1

2

 using stem(x) plots the signal starting from index number 1
CECOS College of Engineering and IT

March – July 2012
Practice
 Plot the following discrete time sequences

x[n]=[1 1 1 1 2 1 1 1 1]

x[n]=[5 4 3 2 1 0 1 2 3 4 5]

CECOS College of Engineering and IT

March – July 2012
Continuous plot
 >> plot(n,x)
 Shows a continuous plot of x
 Actually the discrete points are only connected with
straight lines.

CECOS College of Engineering and IT

March – July 2012
Labeling the plot
 Example:

CECOS College of Engineering and IT

March – July 2012
Labeling the plot

CECOS College of Engineering and IT

March – July 2012
Multiple plots
 Using single “plot” instruction
 Example:

x = 0:0.01:5;
y1=sin(x);
y2=sin(2*x);
y3=sin(4*x);
plot(x,y1,x,y2,x,y3)

CECOS College of Engineering and IT

March – July 2012
Multiple plots

CECOS College of Engineering and IT

March – July 2012
Multiple plots
 Using multiple “plot” instructions
 Example:

x = 0:0.01:5;
y1=sin(x);
y2=sin(2*x);
y3=sin(4*x);
plot(x,y1);
hold on;
plot(x,y2);
plot(x,y3);

CECOS College of Engineering and IT

March – July 2012
Multiple plots

CECOS College of Engineering and IT

March – July 2012
Changing default plot settings
 Example:
x = 0:0.1:5;
y1=sin(x);
y2=sin(2*x);
y3=sin(4*x);

plot(x,y1,’+’,x,y2,':',x,y3,‘--');

CECOS College of Engineering and IT

March – July 2012
Changing default plot settings

CECOS College of Engineering and IT

March – July 2012
Changing default plot settings
 line types and mark types
Linetypes :

solid (-), dashed (--), dotted (:), dashdot (-.)

Marktypes :

point (.), plus (+), star (*), circle (o), x-mark (x)

Check the help of “plot” for more effects.
CECOS College of Engineering and IT

March – July 2012
Axis command
 Used to manually zoom axis
 axis([xmin xmax ymin ymax])
 Example:

CECOS College of Engineering and IT

March – July 2012
Axis command
 Without axis command

CECOS College of Engineering and IT

March – July 2012
Axis command
 With axis command

CECOS College of Engineering and IT

March – July 2012
SUBPLOT
 Example:
x = 0:1:10;
y = x.^2;
z = 10*x;
subplot (1,2,1)

plot(x,y)
subplot (1,2,2)
plot(x,z)
subplot(m,n,p) : makes m rows and n columns of figures in figure window
and p shows the location of the current plot i.e the plot instruction just below
the subplot
CECOS College of Engineering and IT

March – July 2012
SUBPLOT

CECOS College of Engineering and IT

March – July 2012
Generating a sine wave
 Example: creating a 5Hz sine wave, sampled at 8000Hz.
f=5;
fs=8000;
t=[0:1/fs:1];
y=sin(2*pi*f*t);
plot(t,y);

CECOS College of Engineering and IT

March – July 2012
Generating a sine wave
 Observe 5 cycles per second.

CECOS College of Engineering and IT

March – July 2012
Generating a sine wave
 Example: Creating a 1000Hz sine wave, sampled at
8000Hz, and routing it to computer’s soundcard.
f=1000;
fs=8000;
t=[0:1/fs:3];
y=sin(2*pi*f*t);
sound(y,fs);

The sound will be heard for 3 seconds, as dictated by the code
CECOS College of Engineering and IT

March – July 2012
Task
1. Plot the two curves y1 = x2 and y2 = 2x on the same graph using

different plot styles. Label the plot properly
2. Write a MATLAB program that adds the following two signals,
Plot the original signals as well as their sum.
x1[n] = [2 2 2 2 2]
x2[n] = [2 2 2 2 0 0]
3. Scale the amplitude of the following signal by a factor of 2 and
½ and show the scaled signals along with the original.

x(t) = sin(t) + 1/3sin(3t)
CECOS College of Engineering and IT

,

t=0:0.01:10
March – July 2012
Tasks
4. Demonstrate the use of the function ”plot3” to plot a straight
3D line

CECOS College of Engineering and IT

March – July 2012

Contenu connexe

Tendances

Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
TUOS-Sam
 
Permutation graphsandapplications
Permutation graphsandapplicationsPermutation graphsandapplications
Permutation graphsandapplications
Joe Krall
 
Math making connections
Math   making connectionsMath   making connections
Math making connections
courtney.smith
 
ARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATA
ARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATAARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATA
ARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATA
grssieee
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
Aakash deep Singhal
 

Tendances (20)

Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Permutation graphsandapplications
Permutation graphsandapplicationsPermutation graphsandapplications
Permutation graphsandapplications
 
Math making connections
Math   making connectionsMath   making connections
Math making connections
 
ARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATA
ARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATAARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATA
ARCHAEOLOGICAL LAND USE CHARACTERIZATION USING MULTISPECTRAL REMOTE SENSING DATA
 
COLLEGE OF COMPUTING AND INFORMATICS Assignment – 4
COLLEGE OF COMPUTING AND INFORMATICS Assignment – 4COLLEGE OF COMPUTING AND INFORMATICS Assignment – 4
COLLEGE OF COMPUTING AND INFORMATICS Assignment – 4
 
2-Rainbow Domination of Hexagonal Mesh Networks
2-Rainbow Domination of Hexagonal Mesh Networks2-Rainbow Domination of Hexagonal Mesh Networks
2-Rainbow Domination of Hexagonal Mesh Networks
 
AP Calculus Slides December 10, 2007
AP Calculus Slides December 10, 2007AP Calculus Slides December 10, 2007
AP Calculus Slides December 10, 2007
 
Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Ee693 sept2014quizgt2
Ee693 sept2014quizgt2
 
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
 
Concatenate function in Excel - How to combine cell in Excel
Concatenate function in Excel - How to combine cell in ExcelConcatenate function in Excel - How to combine cell in Excel
Concatenate function in Excel - How to combine cell in Excel
 
Ee693 sept2014quizgt1
Ee693 sept2014quizgt1Ee693 sept2014quizgt1
Ee693 sept2014quizgt1
 
Data Science for Number and Coding Theory
Data Science for Number and Coding TheoryData Science for Number and Coding Theory
Data Science for Number and Coding Theory
 
Minimal Introduction to C++ - Part I
Minimal Introduction to C++ - Part IMinimal Introduction to C++ - Part I
Minimal Introduction to C++ - Part I
 
Session II - Estimation methods and accuracy Li-Chun Zhang Discussion: Sess...
Session II - Estimation methods and accuracy   Li-Chun Zhang Discussion: Sess...Session II - Estimation methods and accuracy   Li-Chun Zhang Discussion: Sess...
Session II - Estimation methods and accuracy Li-Chun Zhang Discussion: Sess...
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
 
Combinatorial optimization CO-1
Combinatorial optimization CO-1Combinatorial optimization CO-1
Combinatorial optimization CO-1
 

En vedette (9)

Lab no.06
Lab no.06Lab no.06
Lab no.06
 
matab no9
matab no9matab no9
matab no9
 
communication system Chapter 6
communication system Chapter 6communication system Chapter 6
communication system Chapter 6
 
communication system ch1
communication system ch1communication system ch1
communication system ch1
 
Lab no.07
Lab no.07Lab no.07
Lab no.07
 
communication system Chapter 5
communication system Chapter 5communication system Chapter 5
communication system Chapter 5
 
communication system Chapter 3
communication system Chapter 3communication system Chapter 3
communication system Chapter 3
 
communication system Chapter 4
communication system Chapter 4communication system Chapter 4
communication system Chapter 4
 
communication system Chapter 2
communication system Chapter 2communication system Chapter 2
communication system Chapter 2
 

Similaire à matab no4

Paper computer
Paper computerPaper computer
Paper computer
bikram ...
 
Paper computer
Paper computerPaper computer
Paper computer
bikram ...
 
Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...
Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...
Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...
Cemal Ardil
 

Similaire à matab no4 (20)

python.ppt
python.pptpython.ppt
python.ppt
 
Perm winter school 2014.01.31
Perm winter school 2014.01.31Perm winter school 2014.01.31
Perm winter school 2014.01.31
 
MatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On Plotting
 
Paper computer
Paper computerPaper computer
Paper computer
 
Paper computer
Paper computerPaper computer
Paper computer
 
python.ppt
python.pptpython.ppt
python.ppt
 
Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...
Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...
Neuro -fuzzy-networks-for-identification-of-mathematical-model-parameters-of-...
 
Chapter 1 MATLAB Fundamentals easy .pptx
Chapter 1 MATLAB Fundamentals easy .pptxChapter 1 MATLAB Fundamentals easy .pptx
Chapter 1 MATLAB Fundamentals easy .pptx
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
Seminar psu 20.10.2013
Seminar psu 20.10.2013Seminar psu 20.10.2013
Seminar psu 20.10.2013
 
python.ppt
python.pptpython.ppt
python.ppt
 
L08.pdf
L08.pdfL08.pdf
L08.pdf
 
gmrit-cse
gmrit-csegmrit-cse
gmrit-cse
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
python(1).ppt
python(1).pptpython(1).ppt
python(1).ppt
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
 
Python basics
Python basicsPython basics
Python basics
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Clustering-beamer.pdf
Clustering-beamer.pdfClustering-beamer.pdf
Clustering-beamer.pdf
 
python.ppt
python.pptpython.ppt
python.ppt
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Dernier (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

matab no4

  • 1. Lab No.04 MATLAB graphics Designed by : Dawar Awan dawar@cecos.edu.pk CECOS College of Engineering and IT March – July 2012
  • 2. Discrete signals  Plot the discrete signal x = [1 2 3 4] in MATLAB 4 3 2 1 -1 0 1 2  using stem(x) plots the signal starting from index number 1 CECOS College of Engineering and IT March – July 2012
  • 3. Practice  Plot the following discrete time sequences x[n]=[1 1 1 1 2 1 1 1 1] x[n]=[5 4 3 2 1 0 1 2 3 4 5] CECOS College of Engineering and IT March – July 2012
  • 4. Continuous plot  >> plot(n,x)  Shows a continuous plot of x  Actually the discrete points are only connected with straight lines. CECOS College of Engineering and IT March – July 2012
  • 5. Labeling the plot  Example: CECOS College of Engineering and IT March – July 2012
  • 6. Labeling the plot CECOS College of Engineering and IT March – July 2012
  • 7. Multiple plots  Using single “plot” instruction  Example: x = 0:0.01:5; y1=sin(x); y2=sin(2*x); y3=sin(4*x); plot(x,y1,x,y2,x,y3) CECOS College of Engineering and IT March – July 2012
  • 8. Multiple plots CECOS College of Engineering and IT March – July 2012
  • 9. Multiple plots  Using multiple “plot” instructions  Example: x = 0:0.01:5; y1=sin(x); y2=sin(2*x); y3=sin(4*x); plot(x,y1); hold on; plot(x,y2); plot(x,y3); CECOS College of Engineering and IT March – July 2012
  • 10. Multiple plots CECOS College of Engineering and IT March – July 2012
  • 11. Changing default plot settings  Example: x = 0:0.1:5; y1=sin(x); y2=sin(2*x); y3=sin(4*x); plot(x,y1,’+’,x,y2,':',x,y3,‘--'); CECOS College of Engineering and IT March – July 2012
  • 12. Changing default plot settings CECOS College of Engineering and IT March – July 2012
  • 13. Changing default plot settings  line types and mark types Linetypes : solid (-), dashed (--), dotted (:), dashdot (-.) Marktypes : point (.), plus (+), star (*), circle (o), x-mark (x) Check the help of “plot” for more effects. CECOS College of Engineering and IT March – July 2012
  • 14. Axis command  Used to manually zoom axis  axis([xmin xmax ymin ymax])  Example: CECOS College of Engineering and IT March – July 2012
  • 15. Axis command  Without axis command CECOS College of Engineering and IT March – July 2012
  • 16. Axis command  With axis command CECOS College of Engineering and IT March – July 2012
  • 17. SUBPLOT  Example: x = 0:1:10; y = x.^2; z = 10*x; subplot (1,2,1) plot(x,y) subplot (1,2,2) plot(x,z) subplot(m,n,p) : makes m rows and n columns of figures in figure window and p shows the location of the current plot i.e the plot instruction just below the subplot CECOS College of Engineering and IT March – July 2012
  • 18. SUBPLOT CECOS College of Engineering and IT March – July 2012
  • 19. Generating a sine wave  Example: creating a 5Hz sine wave, sampled at 8000Hz. f=5; fs=8000; t=[0:1/fs:1]; y=sin(2*pi*f*t); plot(t,y); CECOS College of Engineering and IT March – July 2012
  • 20. Generating a sine wave  Observe 5 cycles per second. CECOS College of Engineering and IT March – July 2012
  • 21. Generating a sine wave  Example: Creating a 1000Hz sine wave, sampled at 8000Hz, and routing it to computer’s soundcard. f=1000; fs=8000; t=[0:1/fs:3]; y=sin(2*pi*f*t); sound(y,fs); The sound will be heard for 3 seconds, as dictated by the code CECOS College of Engineering and IT March – July 2012
  • 22. Task 1. Plot the two curves y1 = x2 and y2 = 2x on the same graph using different plot styles. Label the plot properly 2. Write a MATLAB program that adds the following two signals, Plot the original signals as well as their sum. x1[n] = [2 2 2 2 2] x2[n] = [2 2 2 2 0 0] 3. Scale the amplitude of the following signal by a factor of 2 and ½ and show the scaled signals along with the original. x(t) = sin(t) + 1/3sin(3t) CECOS College of Engineering and IT , t=0:0.01:10 March – July 2012
  • 23. Tasks 4. Demonstrate the use of the function ”plot3” to plot a straight 3D line CECOS College of Engineering and IT March – July 2012