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

EXPERIMENT 1

GENERATION OF BASIC SIGNALS


a)
b)
c)
d)
e)

UNIT IMPULSE
UNIT STEP
EXPONENTIAL
RAMP
SINUSODIAL

%program for generating unit step sequence


clearall
closeall
clc
x=[-25:20]
z=[zeros(1,25) ones(1,21)]
stem(x,z)
title('unit step sequence')
xlabel('n')
ylabel('f(n)')

unit step sequence

1
0.9
0.8
0.7

f(n)

0.6
0.5
0.4
0.3
0.2
0.1
0
-25

-20

-15

-10

-5

10

15

20

%program for generating discrete time unit impulse signal


clear all
clc
x=[-20:20];
z=[zeros(1,20) 1 zeros(1,20)];
stem(x,z)
title('unit impulse sequence')
xlabel('n')
ylabel('f(n)')
unit impulse sequence

1
0.9
0.8
0.7

f(n)

0.6
0.5
0.4
0.3
0.2
0.1
0
-20

-15

-10

-5

0
n

%program for generating unit ramp function


clear all
close all
clc
x=[-18:25];
z=((sign(x)+1)/2).*x
stem(x,z)
title('unit ramp signal')
xlabel('n')
ylabel('f(n)')

10

15

20

unit ramp signal

25

20

f(n)

15

10

0
-20

-15

-10

-5

%program for generating signum


clear all
close all
clc
x=[-20:20];
z=sign(x)
stem(x,z)
title('signum')
xlabel('n')
ylabel('f(n)')

10

15

20

25

signum

1
0.8
0.6
0.4

f(n)

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-20

-15

-10

-5

0
n

%program for generating sinc signal


clear all
close all
clc
x=[-10:0.1:10];
z=sinc(x)
stem(x,z)
title('sinc signal')
xlabel('n')
ylabel('f(n)')

10

15

20

sinc signal

1
0.8
0.6

f(n)

0.4
0.2
0
-0.2
-0.4
-10

-8

-6

-4

-2

0
n

%program for generating sinusoidal signal


clear all
close all
clc
k=input('enter constant')%constant=1
x=[-8:0.3:10];
z=sin(k.*x)
stem(x,z)
title('sinusoidal signal')
xlabel('n')
ylabel('f(n)')

10

sinusoidal signal

1
0.8
0.6
0.4

f(n)

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-8

-6

-4

-2

%program for generating triangular signal


clc
clear all
close all
A=1;
w0=10*pi;
w=0.5;
t=-1:0.02:1;
tri=A*sawtooth(w0*t,w);
stem(t,tri)
title('triangular signal')
xlabel('n')
ylabel('f(n)')

10

triangular signal

1
0.8
0.6
0.4

f(n)

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1

-0.8

-0.6

-0.4

-0.2

0
n

0.2

0.4

0.6

%program for generating real exponential signal


clc
clear all
close all
x=[-20:20];
a=input('enter constant')%constant=0.75
z=a.^x;
stem(x,z)
title('real exponential')
xlabel('n')
ylabel('f(n)')

0.8

real exponential

350
300
250

f(n)

200
150
100
50
0
-20

-15

-10

-5

0
n

10

%program for generating complex exponential signal


clc
clear all
close all
x=[-10:0.5:10];
a=input('enter constant')%constant=1.5
y=input('enter frequency')%frequency=60
z=(a.^x).*(exp(j.*(y.*x)+5))
m=real(z)
n=imag(z)
subplot(2,1,1)
stem(x,m)
subplot(2,1,2)
stem(x,n)
title('complex exponential')
xlabel('n')
ylabel('f(n)')

15

20

x 10

0.5
0
-0.5
-1
-10

-8

-6

-4

-2

10

10

complex exponential

5000

f(n)

0
-5000
-10000
-10

-8

-6

-4

-2

0
n

EXPERIMENT 2
BASIC OPERATION ON SIGNALS
a)
b)
c)
d)
e)

Shifting
Folding
Time scaling
Signal addition
Signal multiplication

%program for signal addition


clc
clear all
close all
n1=input('enter sample range for signal 1');%sample range[-10:10]
x1=input('enter range of values for signal 1');%range of values[-10:10]
n2=input('enter sample range for signal 2');%sample range[-5:5]
x2=input('enter range of values for signal 2');%range 0f values[-5:5]
subplot(2,2,1)
stem(n1,x1)
xlabel('n1')
ylabel('x1')
title('input signal 1')
subplot(2,2,2)
stem(n2,x2)
xlabel('n2')
ylabel('x2')
title('input signal 2')
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))))=x1;
y2(find((n>=min(n2))&(n<=max(n2))))=x2;
y=y1+y2;
subplot(2,1,2)
stem(n,y);
xlabel('n')
ylabel('y')
title('signal addition')

input signal 1

10

input signal 2

x2

x1

5
0

-5
-10
-10

-5

0
n1

-5
-5

10

0
n2

signal addition

10

5
0
-5
-10
-10

-8

-6

-4

-2

0
n

10

%program for signal multiplication


clc
clear all
close all
n1=input('enter sample range for signal 1');%sample range[-10:10]
x1=input('enter range of values for signal 1');%range of values[-10:10]
n2=input('enter sample range for signal 2');%sample range[-5:5]
x2=input('enter range of values for signal 2');%range 0f values[-5:5]
subplot(2,2,1)
stem(n1,x1)
xlabel('n1')
ylabel('x1')
title('input signal 1')
subplot(2,2,2)
stem(n2,x2)
xlabel('n2')
ylabel('x2')
title('input signal 2')
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))))=x1;
y2(find((n>=min(n2))&(n<=max(n2))))=x2;
y=y1.*y2;

subplot(2,1,2)
stem(n,y);
xlabel('n')
ylabel('y')
title('signal multiplication')

input signal 1

10

input signal 2

x2

x1

5
0

-5
-10
-10

-5

0
n1

-5
-5

10

0
n2

signal multiplication

25

20
y

15
10
5
0
-10

-8

-6

-4

% program for shifting


clc
clear all
close all
x=[-5:20]
z=[zeros(1,5) ones(1,21)]
subplot(2,2,1)
stem(x,z)

-2

0
n

10

title('unit step')
xlabel('n')
ylabel('f(n)')
x1=x+3
subplot(2,2,2)
stem(x1,z)
title('shifted signal')
xlabel('n')
ylabel('f(n+3)')

%program for folding


clc
clear all
close all
n=input('starting point')%starting point=5
m=input('length')%length=8
p=n+m
x=[n:p]
y=sign(x).*x
subplot(2,2,3)
stem(x,y)
title('sample signal')
x1=-x
subplot(2,2,4)
stem(x1,y)
title('folded signal')

%program for time scaling


clc
clear all
close all
m=input('scaling constant')%m=1
x=input('input sequence')%x=0:10
n=input('sample range')%n=0:5
if m>=1
k=mod(n,m);
j=1;
for l=min(n)+1:max(n)+1
if(k(l)==0)
y(j)=x(l);
j=j+1;
end
end
else
for k=min(n)+1:max(n)+1
y((k/m)+(1/m)-(2/m)+1)=x(k);
end
end
q=length(y);
n=0:q-1;
stem(n,y)
xlabel('n')
ylabel('x[n]')
title('down sampling')
axis([min(n)-2 max(n)+2 min(y)-2 max(y)+2])

down sampling

7
6
5

x [n ]

4
3
2
1
0
-1
-2
-2

-1

EXPERIMENT 3
IMPLEMENTATION OF CONVOLUTION SUM
% program for convolution without using standard commands
clc
clear all
close all
x=[1 2 3 4 5]
h=[40 41 42 43 44 45 46 47]
m=length(x);
n=length(h);
if(m>=n)
p=m;
else
p=n;
end
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:p
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
stem(Y);
ylabel('Y[n]');
xlabel('n');
title('convolution of two signals without conv function');

convolution of two signals without conv function

700
600
500

Y[n]

400
300
200
100
0

6
n

% program for overlap add convolution


clc
clearall
closeall
x=[1 3 5 7 9 11 12 13 14 17]
h=[10 5 2]
cconv(x,h)
p=length(x);
q=length(h);
if(p>=q)
N=p;
else
N=q;
end
x1=zeros(1,10);
Nx=length(x);
M=length(h);
L=ceil(N-M+1);
h=[h zeros(1,N-M)];
d=floor(Nx/L);
for j=0:d-1
k=1:L;
x1(k)=x(k+j*L);
x1=[x, zeros(1,N-L)];
r=1:j*L+1;
z(j+1,r)=0;
y=cconv(x1,h,N);

10

12

t=1:N;
z(j+1,t+j*L)=y(t);
end
for j=1:length(z)
b(j)=0;
for k=1:d
b(j)=b(j)+z(k,j);
end
end
stem(b);

450
400
350
300
250
200
150
100
50
0

EXPERIMENT 5

10

COMPUTATION OF DFT
% program for computation of DFT

im aginary part of x (n)

real part:x (n)

for t=1:45
h(t)=sin(2*pi*(11^11)*t)
end
N=length(h)
n=1:N
y=0
for k=1:N
y=y+h(k)*exp(-j*2*pi*(k-1)*(n-1)/N)
end
subplot(3,1,1)
stem(n,real(y))
title('spectrum of given signal:real part')
xlabel('n')
ylabel('real part:x(n)')
subplot(3,1,2)
stem (n,imag(y))
title('spectrum of given signal:imag part')
xlabel('n')
ylabel('imaginary part of x(n)')
subplot(3,1,3)
stem(n,angle(y))
xlabel('phase')
ylabel('n')
title('angle plot')

spectrum of given signal:real part

0.1
0
-0.1

10

15

20

10

15

20

25
n
angle plot

10

15

20
25
phase

0.05

25
30
n
spectrum of given signal:imag part

35

40

45

30

35

40

45

30

35

40

45

0
-0.05

5
0
-5

EXPERIMENT 4

COMPUTATION OF IMPULSE RESPONSE OF THE LTI SYSTEM


% program for impulse response
clc
clearall
closeall
x=input('enter the input coefficients=');%x=20
y=input('enter the output coefficients=');%y=20
m=input('enter start of sequence with negative value');%m=-2
n=input('enter length of sequence');%n=30
p=m;
q=m+n;
z=p:q;
w=-p;
i=[zeros(1,w) 1 zeros(1,q)];
X1=filter(x,y,i);
figure;
stem(z,X1);
xlabel('sample range')
ylabel('y(n)')
title('impulse response')

impulse response

1
0.9
0.8
0.7

y (n )

0.6
0.5
0.4
0.3
0.2
0.1
0
-5

10
15
sample range

20

25

30

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