Index: Exp No. Experiment Name Date of Performance Date of Checking Signature Marks
Index: Exp No. Experiment Name Date of Performance Date of Checking Signature Marks
Index: Exp No. Experiment Name Date of Performance Date of Checking Signature Marks
x(n) = 1 0=<n<=3
=0 elsewhere
4. An LTI system is specified by the
difference equation
Y(n)=0.9*y(n-1)+x(n)
a) Determine H(exp(jw))
b) Calculate & plot the steady state
response
EXPERIMENT No. – 1
AIM
Program for generation of sin, cos, exponential, unit impulse, step function, square wave.
THEORY
Sine Function:
A function f(x)=sin(x) is a periodic function with a period of 2∏, it will form a periodic wave
after 2∏. The f(x) will lie between -1 to +1.
Cosine Function:
A function f(x)=cos(x) is a periodic function with a period of 2∏, it will form a periodic wave
after 2∏.
Exponential Function:
Unit impulse is a signal that is 0 everywhere except at n=0 where it is 1. In discrete time domain
the unit impulse signal is defined as:
The integral of the impulse function is a unit step signal. In discrete time unit step signal is
defined as:
CODE:
t=0:0.01:pi;
x=sin(2*pi*t);
y=cos(2*pi*t);
z1=exp(2* t);
z2=exp(2*(-t));
subplot(221);
plot(x);
xlabel('Time');
ylabel('Amplitude');
title('Cosine Wave');
subplot(223);
plot(z1);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Rising');
subplot(224);
plot(z2);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Falling');
h(5)=1;
for i=1:4
h(i)=0;
end;
for i=6:10
h(i)=0;
end;
m=-4:5;
figure;
subplot(221);
stem(m,h);
xlabel('Time');
ylabel('Amplitude');
title('Unit Impulse');
for j=1:4
g(j)=0;
end;
for j=5:10
g(j)=1;
end;
subplot(212);
stem(m,g);
xlabel('Time');
yabel('Amplitude');
title('Step Function');
a=1;b=5;c=6;d=10;
for p=1:4
for k=a:b
s(k)=1;
end;
for k=c:d
s(k)=-1;
end;
a=a+10;
b=b+10;
c=c+10;
d=d+10;
end;
n=0:39;
figure;
subplot(211);
stem(n,s);
xlabel('Time');
ylabel('Amplitude');
title('Square Wave');
v=0:5;
subplot(212);
stem(v,v);
xlabel('Time');
ylabel('Amplitude');
title('Ramp');
OUTPUT
EXPERIMENT No. – 2(a)
AIM
To generate convolved output of two sample sequences.
THEORY
A convolution is an integral that expresses the amount of overlap of one function as it is shifted
over another function. It therefore “blends” from one function to another. For example, in
synthesis imaging, the measured dirty map is a convolution of the “true” CLEAN map with the
dirty beam.
Y(n)= ∑ x(k)h(n-k)
This formula gives response y(n) of the LTI system as a function of the input signal x(n) and the
unit sample response h(n) is called CONVOLUTION SUM.
We say that the input x(n) is convolved with the impulse response h(n) to yield the output y(n).
The process of computing the convolution between x(k) and h(k) involves the following steps:
3. Multiplication: Multiply x(k) by h(n-k) to obtain the value of the output sequence
v(k) = x(k)h(n-k).
4. Summation: Sum all the values of the product sequence v(k) to obtain the value of the output
at a given time .
PROPERTIES OF CONVOLUTION
1. COMMUTATIVE LAW:
x(n)*h(n) = h(n)* x(n)
2. ASSOCIATIVE LAW:
[x(n)*h1(n)]*h2(n) = x(n)*[h1(n)*h2(n)]
3. DISTRIBUTIVE LAW:
x(n)*[h1(n)+h2(n)] = x(n)*h1(n) + x(n)*h2(n)
CODE:
x=[1 1 1 1 1 0 0 0 0 0 0 0 0 0]
h=[1 1 1 1 1 0 0 0 0 0 0 0 0 0]
k1=0;
k2=0;
k3=4;
k4=4;
ley=k1+k2;
rey=k3+k4;
for n=(ley:rey)
n1=n+1;
y(n1)=0;
for k=k1:(n-k2)
a=k+1;
b=(n-k)+1;
if b<=0
break;
end
y(n1)=y(n1)+((x(a)).*(h(b)));
end
end
n=ley:rey;
figure;
stem(n,y);
Xlabel('Time');
Ylabel('Amplitude');
Title('Convolved Output');
OUPTUT
EXPERIMENT No. – 2(b)
AIM
THEORY:
Suppose that we have two signal sequences x(n) and y(n) each of which has finite energy.
The cross correlation of x(n) and y(n) is a sequence rxy(l), which is defined as
or equivalently as
the index l is the time shift (or lag) parameter and the subscript xy on the cross correlation
sequence r xy (l) indicates the sequence being correlated. The order of the subscript, with x
preceding y, indicates the direction in which one sequence is shifted relative to other.
If we reverse the role of x(n) and y(n) in above equation we obtain the correlation sequence
or equivalently as
r xy (l) = r yx (-l)
therefore r yx (l) is simply folded version of r xy (l) where the folding is done with respect to
l=0.
In the special case where y(n)=x(n) , we have AUTOCORRELATION of x(n) which is defined
as the sequence
or equivalently as
CONCLUSION: The convolution of two discrete time signals has been found resultant signal is
shown wave form.
CODE:
x=[2 -1 3 7 1 2 -3 0 0 0 0 0 0 0];
y=[0 0 0 0 0 0 0 0 0 1 -1 2 -2 4 1 -2 5];
h=fliplr(y);
k1=-4;
k2=-3;
k3=2;
k4=4;
ler=k1+k2;
rey=k3+k4;
for n=ler:rey
n1=n+8;
r(n1)=0;
for k=k1:(n1-k2)
a=k+5;
b=(n-k)+4;
if b<=0
break;
end
r(n1)=r(n1)+((x(a)).*(h(b)));
end
end
n=ler:rey;
stem(n,r);
xlabel('time');
ylabel('amplitude');
title('correlated output->y');
OUTPUT
EXPERIMENT No.- 3
AIM
CODE:
sum=0;
p=1;
x=[1 1 1 1];
for w = 0: (pi/100) : (2*pi)
sum=0;
for i=0:3
y=x(i+1)*exp(-j*w*i);
sum=sum+y;
end
X(p)=sum;
p=p+1;
end
t=0:0.01:2
subplot(211);
plot(t,abs(X));
title('Magnitude Plot');
subplot(212);
plot(t,phase(X));
title('Phase Plot');
OUTPUT
EXPERIMENT No.- 4
AIM
An LTI system is specified by the difference equation
Y(n)=0.8*Y(n-1)+x(n)
(a) Determine H(exp(jw))
(b) Calculate & plot the steady state response
Yss (n) to x(n)=cos(0.5∏n) u(n)
THEORY
Y(n) = 0.8Y(n-1)+x(n)
Taking DTFT
Hence
H(w) = Y(ejw)/x(ejw)
= 1/[1-0.8 ejw]
Now,
Y(n)=x(n)*h(n)
Y(n)=∑ h(k).x(n-k)
Here,
Y(n)=4.029 cos(0.5∏(n-3.4321))
CODE:
n=0:100;
x=cos(0.05*pi*n);
y=0.0927*cos(0.05*pi*(n-3.4231));
figure;
subplot(211);
stem(n,x);
title('input');
subplot(212);
stem(n,y);
title('output');
Output
EXPERIMENT No. - 5
AIM
THEORY
y(n)=0.9*y(n-1)+x(n)
Y(z)-0.9*z-1Y(z)=X(z)
Or, Y(z)[1-0.9*z-1]=X(z)
This gives,
H(z)=1/(1-0.9z-1)
The pole of the system is lying at, z=0.9, which is inside the unit circle. Also, the condition for
stability is that poles must lie inside the circle for the system to be stable. Here, the pole z=0.9 is
lying inside of the unit circle. So, the system is stable.
CODE:
zplane(0,0.09);
k=1;
for w=0:0.01:(2*pi);
h(k)=1/(1-(0.9*exp(-j*w)));
k=k+1;
end;
w=0:0.01:(2*pi);
figure;
subplot(211);
plot(w,abs(h));
title('magnitude of h(e(jw))');
subplot(212);
plot(w,angle(h));
title('angle of h(e(jw))');
OUTPUT
EXPERIMENT NO.6
AIM:
Let x(n) be 4 point sequence
X(n)=1 ; 0=< n =<3
=0 ; elsewhere
Compute the 4-point DFT, 8-point DFT, and 16-point DFT and plot their magnitude and phase
plot.
THEORY:
The discrete Fourier transform computes the values of the z transform for evenly spaced points
around the unit circle for a given sequence.
If the sequence to be represented is of finite duration, i.e., has only a finite number of non-zero
values, the transform is discrete Fourier transform.
N-1
4-point DFT
N=4
N-1
8-point DFT
N=8
X(n) = {1,1,1,1,0,0,0,0}
N-1
CODE:
x= [1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0];
N4=4;
for k=0: N4-1
k1=k+1;
y4 (k1) =0;
for n=0 : 3
n1=n+1;
y4 (k1) =y4 (k1) + ((x (n1)) .* (exp (-j*(2*pi*k*n)/N4)));
end
end
N8=8;
for k=0 : N8-1
k1=k+1;
y8 (k1) =0;
for n=0: 3
n1=n+1;
y8 (k1) =y8 (k1) + ((x (n1)) .* (exp (-j*(2*pi*k*n)/N8)));
end
end
N16=16;
for k=0 : N16-1
k1=k+1;
y16 (k1) =0;
for n=0 : 3
n1=n+1;
y16 (k1) =y16 (k1) + ((x (n1)) .* (exp (-j*(2*pi*k*n)/N16)));
end
end
k4=0 : N4-1;
figure;
subplot (211);
stem (k4, abs (y4));
title (‘magnitude of 4-point DFT’);
subplot (212);
stem (k4, angle (y4));
title (‘angle of 4-point DFT’);
k8=0 : N8-1;
figure;
subplot (211);
stem (k8, abs (y8));
title (‘magnitude of 8-point DFT’);
subplot (212);
stem (k8, angle (y8));
title (‘angle of 8-point DFT’);
k16=0 : N16-1;
figure;
subplot (211);
stem (k16, abs (y16));
title (‘magnitude of 16-point DFT’);
subplot (212);
stem (k16, angle (y16));
title (‘angle of 16-point DFT’);
OUTPUT:
magnitude of 4-point DFT
4
0
0 0.5 1 1.5 2 2.5 3
-1
-2
-3
0 0.5 1 1.5 2 2.5 3
magnitude of 8-point DFT
4
0
0 1 2 3 4 5 6 7
-2
-4
0 1 2 3 4 5 6 7
magnitude of 16-point DFT
4
0
0 5 10 15
-2
-4
0 5 10 15
CONCLUSION:
The magnitude and phase of 4-point, 8-point, 16-point DFT has been computed and is shown in
figure.
EXPERIMENT NO.7(a)
AIM
Differentiate between high density high resolutions spectrums. For given sequence:
X(n)=cos(0.48*pi*n) + cos(0.52*pi*n)
Determine DFT & also plot it for 0<=n<=10
CODE:
n=0:10
x=cos(0.48*pi*n)+cos(0.52*pi*n);
p=1;
N=11;
for w=0:pi/100:2*pi;
sum=0;
for n=0:N-1;
sum=sum+(x(n+1)*exp(-j*w*n));
end
y(p)=sum;
p=p+1;
end
figure;
magx=abs(y);
phasex=angle(y);
subplot(311);
stem(x);
xlabel('x--> ');
ylabel('y-->');
subplot(312);
plot(magx);
xlabel('x--->');
ylabel('y--->');
subplot(313);
plot(phasex);
xlabel('x--->');
ylabel('y--->');
OUTPUT
EXPERIMENT NO.7(b)
AIM
Differentiate between high density high resolutions spectrums. For given sequence:
X(n)=cos(0.48*pi*n) + cos(0.52*pi*n)
Determine DFT & also plot it for 0<=n<=100
CODE:
n=0:100
x=cos(0.48*pi*n)+cos(0.52*pi*n);
p=1;
N=101;
for w=0:pi/100:2*pi;
sum=0;
for n=0:N-1;
sum=sum+(x(n+1)*exp(-j*w*n));
end
y(p)=sum;
p=p+1;
end
figure;
magx=abs(y);
phasex=angle(y);
subplot(311);
stem(x);
xlabel('x--> ');
ylabel('y-->');
subplot(312);
plot(magx);
xlabel('x--->');
ylabel('y--->');
subplot(313);
plot(phasex);
xlabel('x--->');
ylabel('y--->');
OUTPUT
EXPERIMENT No. – 8
AIM
Program to find circular convolution of two sequences x(n) & h(n)
CODE:
x = [1 2 2 0]
h = [1 2 3 4]
length_x = length(x);
length_h = length(h);
if length_x ~= length_h;
rest = abs(length_x - length_h);
a = zeros(1,rest);
if length_x > length_h;
h = [h,a]
length_h = length(h);
else
x = [x,a]
length_x = length(x);
end;
end;
for n = 1 : length_x;
sum = 0;
for m = 1 : length_x;
if (n-m+1) < 1;
t = n-m+length_x+1;
else
t = n-m+1;
end;
sum = sum + (x(m) * h(t));
end;
result(n) = sum;
end;
result
figure(1);
subplot(3,1,1);
stem(x);
xlabel('n ----->');
ylabel('x(n) ----->');
subplot(3,1,2);
stem(h);
xlabel('n ----->');
ylabel('h(n) ----->');
subplot(3,1,3);
stem(result);
xlabel('n ----->');
ylabel('y(n) ----->');
OUTPUT
EXPERIMENT No.-9
AIM
To design a FIR low pass filter using Rectangular, Barlett, Hamming, Hanning & Blackmann
window & to plot the frequency response of filter. The specification of the filter are as follows:
THEORY
The Image Processing Toolbox supports one class of linear filter, the two-dimensional
finite impulse response (FIR) filter. FIR filters have several characteristics that make
them ideal for image processing in the MATLAB environment:
Another class of filter, the infinite impulse response (IIR) filter, is not as suitable for
image processing applications. It lacks the inherent stability and ease of design and
implementation of the FIR filter. Therefore, this toolbox does not provide IIR filter support.
Windowing Method
The windowing method involves multiplying the ideal impulse response with a window
function to generate a corresponding filter. Like the frequency sampling method, the
windowing method produces a filter whose frequency response approximates a desired
frequency response. The windowing method, however, tends to produce better results
than the frequency sampling method.
The toolbox provides two functions for window-based filter design, fwind1 and
fwind2. fwind1 designs a two-dimensional filter by using a two-dimensional window
that it creates from one or two one-dimensional windows that you specify. fwind2
designs a two-dimensional filter by using a specified two-dimensional window directly.
fwind1 supports two different methods for making the two-dimensional windows it
uses:
ws=.3
wp=.2
as=50
rp=.25
dp=(1-exp(-rp/20))/(1+exp(-rp/20));
ds=exp(-as/20)+dp*exp(-rp/20);
num=-20*log10(sqrt(dp*ds))-13;
den=(14.6*(ws-wp))/2*pi;
N=ceil(num/den);
tr=ws-wp;
M=(4*pi)/tr;
wc=(ws+wp)/2;
alpha=(M-1)/2;
hd=sin(wc*(M-alpha))/(pi*(M-alpha));
A=boxcar(M);
h=hd*A;
figure(1);
freqz(h);
M=(8*pi)/tr;
hd=sin(wc*(M-alpha))/(pi*(M-alpha));
A=hamming(M);
h=hd*A;
figure(2);
freqz(h);
M=(8*pi)/tr;
hd=sin(wc*(M-alpha))/(pi*(M-alpha));
A=hanning(M);
h=hd*A;
figure(3);
freqz(h);
M=(8*pi)/tr;
hd=sin(wc*(M-alpha))/(pi*(M-alpha));
A=bartlett(M);
h=hd*A;
figure(4);
freqz(h);
M=(12*pi)/tr;
hd=sin(wc*(M-alpha))/(pi*(M-alpha));
A=blackman(M);
h=hd*A;
figure(5);
freqz(h);
OUTPUT
EXPERIMENT No. - 10
AIM
THEORY
In this technique the desired impulse response of the digital filter is obtained by uniformly
sampling the impulse response of the analog filter.
H(s) = (s+1)/(s2+5s+6)
Bilinear Transformation
In this technique the desired impulse response of the digital filter is obtained uniformly sampling
the impulse response of the analog filter.
Taking T=1sec.
H(z)=(0.15-0.1z-1-0.05z-2)/(1+0.2z-1)
CODE:
******************************
Impulse Invariant Method
******************************
T=0.1;
c=[1 1];
d=[1 5 6];
[r p k]=residue(c,d);
p=exp(p*T);
[b a]=residuez(r,p,k);
b=real(b);
a=real(a);
******************************
Bilinear Transformation Method
******************************
c=[1 1]
d=[1 5 6]
T=1
Fs=1/T
[b,a]=bilinear(c,d,Fs)
Output
******************************
Impulse Invariant Method
******************************
T= 0.1000
c= 1 1
d= 1 5 6
r= 2.0000
-1.0000
p= -3.0000
-2.0000
k= []
p= 0.7408
0.8187
b= 1.0000 -0.8966
b= 1.0000 -0.8966
******************************
Bilinear Transformation Method
******************************
c= 1 1
d= 1 5 6
T= 1
Fs = 1