Date post: | 08-Jul-2015 |
Category: |
Education |
Upload: | moeen-khan-afridi |
View: | 48 times |
Download: | 1 times |
MATLAB graphics
Designed by : Dawar [email protected]
March – July 2012CECOS College of Engineering and IT
Lab No.04
March – July 2012CECOS College of Engineering and IT
Plot the discrete signal x = [1 2 3 4] in MATLAB
using stem(x) plots the signal starting from index number 1
Discrete signals
1
2
3
4
-1 0 1 2
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]
Practice
March – July 2012CECOS College of Engineering and IT
March – July 2012CECOS College of Engineering and IT
Continuous plot
>> plot(n,x)
Shows a continuous plot of x
Actually the discrete points are only connected with
straight lines.
March – July 2012CECOS College of Engineering and IT
Labeling the plot
Example:
March – July 2012CECOS College of Engineering and IT
Labeling the plot
March – July 2012CECOS College of Engineering and IT
Multiple plots
x = 0:0.01:5;
y1=sin(x);
y2=sin(2*x);
y3=sin(4*x);
plot(x,y1,x,y2,x,y3)
Using single “plot” instruction
Example:
March – July 2012CECOS College of Engineering and IT
Multiple plots
March – July 2012CECOS College of Engineering and IT
Multiple plots
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);
Using multiple “plot” instructions
Example:
March – July 2012CECOS College of Engineering and IT
Multiple plots
March – July 2012CECOS College of Engineering and IT
Changing default plot settings
x = 0:0.1:5;
y1=sin(x);
y2=sin(2*x);
y3=sin(4*x);
plot(x,y1,’+’,x,y2,':',x,y3,‘--');
Example:
March – July 2012CECOS College of Engineering and IT
Changing default plot settings
March – July 2012CECOS College of Engineering and IT
Changing default plot settings
line types and mark types
Check the help of “plot” for more effects.
Linetypes : solid (-), dashed (--), dotted (:), dashdot (-.)
Marktypes : point (.), plus (+), star (*), circle (o), x-mark (x)
March – July 2012CECOS College of Engineering and IT
Axis command
Used to manually zoom axis
axis([xmin xmax ymin ymax])
Example:
March – July 2012CECOS College of Engineering and IT
Axis command
Without axis command
March – July 2012CECOS College of Engineering and IT
Axis command
With axis command
March – July 2012CECOS College of Engineering and IT
SUBPLOT
x = 0:1:10;
y = x.^2;
z = 10*x;
subplot (1,2,1)
plot(x,y)
subplot (1,2,2)
plot(x,z)
Example:
subplot(m,n,p) : makes m rows and n columns of figures in figure windowand p shows the location of the current plot i.e the plot instruction just below the subplot
March – July 2012CECOS College of Engineering and IT
SUBPLOT
March – July 2012CECOS College of Engineering and IT
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);
March – July 2012CECOS College of Engineering and IT
Generating a sine wave
Observe 5 cycles per second.
March – July 2012CECOS College of Engineering and IT
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
March – July 2012CECOS College of Engineering and IT
Task1. Plot the two curves y1 = x 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) , t=0:0.01:10
2
March – July 2012CECOS College of Engineering and IT
Tasks
4. Demonstrate the use of the function ”plot3” to plot a straight 3D line