signals in matlab
TRANSCRIPT
Signal in MATLAB
04/12/2023
DOES - PC
>> y = sin(linspace(0,2*pi,10));>> stem(y)
1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Sine Wave:
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
x = 0:2
Sin
e of
x
Plot of the Sine Function
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y)
OR
>> y = cos(linspace(0,2*pi,10));>> stem(y)
Cosine Wave:
1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
x = 0:2
Sin
e of
x
Plot of the Sine Function
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y)
OR
Multiple Signals:
>> x = 0:pi/100:2*pi;>> y = sin(x);>> y2 = sin(x-.25);>> y3 = sin(x-.5)>> plot(x,y,x,y2,x,y3)
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Multiple Plots:
t = 0:pi/100:2*pi;y1=sin(t);y2=sin(t+pi/2);subplot(2,2,1)plot(t,y1)subplot(2,2,2)plot(t,y2);subplot(2,2,3)plot(t,y1)subplot(2,2,4)plot(t,y2);
0 2 4 6 8-1
-0.5
0
0.5
1
0 2 4 6 8-1
-0.5
0
0.5
1
0 2 4 6 8-1
-0.5
0
0.5
1
0 2 4 6 8-1
-0.5
0
0.5
1
Square Wave Wave:
0 50 100-1
-0.5
0
0.5
1
Time
Am
plitu
de
Squarewave
0 50 100-1
-0.5
0
0.5
1
Time
Am
plitu
de
Square wave
>> t:0:100;>> y=square(2*pi*100*t/100,50);>> plot(t,y)>> stem(t,y)
Ramp Signal:
0 5 10 15 200
5
10
15
20
sequence
Am
plitu
de
Ramp Signal
0 5 10 15 200
5
10
15
20
sequence
Am
plitu
de
Ramp Signal
> > t:0:20;>> plot(t,t);>> stem(t,t)
Exponential Signal:
>> t=0:20;>> y2=exp(t);>> plot(t,y2)>> stem(t,y2)
0 5 10 15 200
2
4
6x 10
8
sequence
Am
plitu
de
Exponential Signal
0 5 10 15 200
2
4
6x 10
8
sequence
Am
plitu
de
Exponential Signal
Impulse Signal:
-2 -1 0 1 20
0.5
1
time
Am
plitu
de
unit impulse signal
-2 -1 0 1 20
0.5
1
time
Am
plitu
de
unit impulse signal
>> t=-2:1:2;>> y=[zeros(1,2),ones(1,1),zeros(1,2)];>> plot(t,y);>> stem(t,y);
Step Signal:
0 5 10 15 200
0.5
1
1.5
2
No of sequence
Am
plitu
de
Unit step sequence
0 5 10 15 200
0.5
1
No of sequence
Am
plitu
de
Unit step sequence
>> t=0.1:n-1;>> y1=ones(1,n-1);>> plot(t,y1)>> stem(t,y1)
Graph Functions:
• plot linear plot• stem discrete plot• grid add grid lines• xlabel add X-axis label• ylabel add Y-axis label• title add graph title• subplot divide figure window • figure create new figure window• pause wait for user response