Вы находитесь на странице: 1из 10

Subhan ullah Roll no 44 section B

LAB#01
TASK 1:

Generation of sinusoidal signals .

Code:
t=[-5:0.01:5];
x=2*sin((2*pi*t)-(pi/2));
plot(t,x)
grid on;
axis([-6 6 -3 3])
ylabel('AMPLITUDE')
xlabel('time')
title('sine wave')

graph:
sine wave
3

1
AMPLITUDE

-1

-2

-3
-6 -4 -2 0 2 4 6
time

TASK 2:
Plot the given Discrete time Signal.

Code:
n =[-5:5];
x=[0 0 1 1 -1 0 2 -2 3 0 -1]
stem(n,x)
grid on;
ylabel('AMPLITUDE')
xlabel('time')
title('x[n]')
Subhan ullah Roll no 44 section B

graph:

x[n]
3

2.5

1.5
AMPLITUDE

0.5

-0.5

-1

-1.5

-2
-5 -4 -3 -2 -1 0 1 2 3 4 5
time

TASK 3:
Make a function named impseq and use this function to plot impulse function .

Code:
Subhan ullah Roll no 44 section B

Graph:

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 1 2 3 4 5 6 7 8 9 10

TASK:4
Make a function named stepseq to plot unit step sequence.

Code:
Subhan ullah Roll no 44 section B

graph:

1
data1
0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 1 2 3 4 5 6 7 8 9 10

TASK:5
Code:

graph:

x[n]
1

0.9

0.8

0.7

0.6
AMPLITUDE

0.5

0.4

0.3

0.2

0.1

0
0 1 2 3 4 5 6 7 8 9 10
time
Subhan ullah Roll no 44 section B

TASK:6
Signal addition.

Code:
function [y,n] = sigadd(x1,n1,x2,n2);
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1 + y2;
return

clear all
close all
clc
n1=[0:10];
x1=sin(n1);
n2=[-5:7];
x2=4*sin(n2);
[y,n]=sigadd(x1,n1,x2,n2);
subplot(3,1,1);
stem(n1,x1);
grid on;
axis([-5 10 -5 5]);
ylabel('x1');
xlabel('n1');
title(' 1st signal ');
subplot(3,1,2);
stem(n2,x2);
grid on;

axis([-5 10 -5 5]);
ylabel('x2');
xlabel('n2');
title(' 2nd signal ');
Subhan ullah Roll no 44 section B

graph:

1st signal
5
x1

-5
-5 0 5 10
n1
2nd signal
5
x2

-5
-5 0 5 10
n2
added signal
5

0
n

-5
-5 0 5 10
y(n)

TASK:7
Code:
function [y,n] = sigmult(x1,n1,x2,n2)
% y(n) = x1(n) * x2(n)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n)); y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y = y1 .* y2;
clear all
close all
clc
n1=[0:10];
x1=sin(n1);
n2=[-5:7];
x2=4*sin(n2);
[y,n]=sigmult(x1,n1,x2,n2);
subplot(3,1,1);
stem(n1,x1);
grid on;
axis([-5 10 -5 5]);
ylabel('x1');
xlabel('n1');
title(' 1st signal ');
subplot(3,1,2);
stem(n2,x2);
grid on;
Subhan ullah Roll no 44 section B
axis([-5 10 -5 5]);
ylabel('x2');
xlabel('n2');
title(' 2nd signal ');
subplot(3,1,3);
stem(n,y,'r');
ylabel('n');
xlabel('y(n)');
title(' mult signal ');
graph:

1st signal
5
x1

-5
-5 0 5 10
n1
2nd signal
5
x2

-5
-5 0 5 10
n2
mult signal
4

2
n

0
-5 0 5 10
y(n)
Subhan ullah Roll no 44 section B

POST LAB:
a. Write MATLAB code to plot these signals:
TASK1:

Code:
function [y,n] = sigadd(x1,n1,x2,n2);
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1 + y2;
return
clear all
close all
clc
n1=[0:10];
x1=2*sin(3*n1);
n2=[-5:7];
x2=2*cos(3*n2);
[y,n]=sigadd(x1,n1,x2,n2);
subplot(3,1,1);
stem(n1,x1);
grid on;
axis([-5 10 -5 5]);
ylabel('x1');
xlabel('n1');
title(' 1st signal ');
subplot(3,1,2);
stem(n2,x2);
grid on;

axis([-5 10 -5 5]);
ylabel('x2');
xlabel('n2');
title(' 2nd signal ');
subplot(3,1,3);
stem(n,y,'r');
ylabel('n');
xlabel('y(n)');
title(' added signal ');
Subhan ullah Roll no 44 section B

graph:

1st signal
5
x1

-5
-5 0 5 10
n1
2nd signal
5
x2

-5
-5 0 5 10
n2
added signal
2

0
n

-2
-5 0 5 10
y(n)

TASK 2:

Code:
function [y,n] = sigadd(x1,n1,x2,n2);
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1 + y2;
return

clear all
close all
clc
n1=[0:10];
x1=heaviside(n1)
n2=[-5:7];
x2=4*cos(3*n2);
[y,n]=sigadd(x1,n1,x2,n2);
subplot(3,1,1);
stem(n1,x1);
grid on;
axis([-5 10 -5 5]);
ylabel('x1');
xlabel('n1');
title(' 1st signal ');
subplot(3,1,2);
stem(n2,x2);
grid on;
Subhan ullah Roll no 44 section B
axis([-5 10 -5 5]);
ylabel('x2');
xlabel('n2');
title(' 2nd signal ');
subplot(3,1,3);
stem(n,y,'r');
ylabel('n');
xlabel('y(n)');
title(' added signal ');

graph:

1st signal
5
x1

-5
-5 0 5 10
n1
2nd signal
5
x2

-5
-5 0 5 10
n2
added signal
5

0
n

-5
-5 0 5 10
y(n)

Вам также может понравиться