You are on page 1of 41

INDEX

Exp No. 1.

Experiment Name Program for generation of sin, cos, exponential, unit impulse, step function, square wave a) Program to determine convolution of two sequences b) Program to determine correlation of two sequences To calculate DTFT & plot magnitude & phase response of following sequence x(n) = 1 0=<n<=3 =0 elsewhere 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

Date of Performance

Date of Checking

Signature

Marks (10)

2.

3.

4.

5.

Y(n) to X(n) = cos(0.5n)u(n) Given a causal system Y(n) = 0.9*y(n-1)+x(n) a) Find H(2) & sketch its pole zero plot b) Plot H(w) & angle H(w) Let X(n) be a 4point sequence X(n) = 1 0<n<3 =0 elsewhere compute the 4-point, 8-point, 16-point DFT & plot magnitude & phase plot

6.

7.

Differentiate b/w high density high resolution spectrum, for given sequence X(n)=cos(0.48*pi*n)+cos(0.52*pi*n) a) Determine DFT & also plot it for 0<=n<=10 & 0<=n<=100 Program to find the circular convolution of two sequences x(n) & h(n) To design a FIR LPL filter using Rectangular, Barlett, Hamming, Hanning, Blackmann Window & plot the phase response of filter. The specification of the filter are as follows: Wp=0.5*pi, Ws=0.3*pi, 0.25dB, As=50 dB Transform H(s)=(s+1)/(s2+5s+6) into a digital filter using a) Impulse Invariant Transformation b) Bilinear Transformation

8.

9.

10.

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: A function f(x)=ex is defined as: 0<f(x)1; 1f(x)<; for -x0 for 0x

Unit impulse 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: (n) =1; = 0; n=0 elsewhere

Unit Step Function: The integral of the impulse function is a unit step signal. In discrete time unit step signal is defined as: U(n) =1; = 0; n>=0 n<0

Square Wave Function: It is a periodic function with a period of T. If f(x) is a square wave function then F(x) = 1; 0<x<T/2 = -1; T/2<x<T

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: 1. Folding: Fold h(k) about k=0 to obtain h(-k). 2. Shifting: Shift h(-k) by n to the right(left) if n is positive(negative) to obtain h(n-k). 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
To determine the correlation of two sequences.

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 r xy (l) = or equivalently as r xy (l) = x(n+l) y(n) x(n) y(n-l)

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 r yx (l) = or equivalently as r yx (l) = by comparing the equations 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 r xx (l) = or equivalently as r xx (l) = x(n+l) x(n) x(n) x(n-l) y(n+l) x(n) y(n) x(n-l)

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 To determine DTFT of a given sequence 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.5n) u(n)

THEORY
Y(n) = 0.8Y(n-1)+x(n) Taking DTFT Y(ejw) = 0.8 e-jwY(ejw) + x(ejw) 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)= cos(0.5n)u(n), then

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
Given a causal system y(n)=0.9y(n-1)+x(n) (a) Find H(z) & sketch its pole - zero plot (b) Plot magnitude & angle of H(exp(jw)) (c) Comment on the stability of the system

THEORY
The given difference equation is, y(n)=0.9*y(n-1)+x(n) Now, taking z-transform we get, Or, 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. Y(z)-0.9*z-1Y(z)=X(z) Y(z)[1-0.9*z-1]=X(z)

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

X(k) = x(n) e-j2


n=0

kn/N

k = 0,1,2..,N-1 x(n) = {1,1,1,1} 4-point DFT N=4


N-1

X(k ) = x(n) e-j2


n=0

kn/N

k = 0,1,2..,N-1
3

X(k) = x(n) e-j2


n=0

kn/4

k = 0,1,2,3 X(k) = x(0)+x(1) e X(0) = 1+1+1+1=4 X(1) = 1+ e-j2 /4 +e-j2 =0 X(2) = 1+ e-j2
2 /4 2/4 -j2k/4

+x(2) e
3/4

-j2k2/4

+x(3) e-j2

k3/4

+e-j2

+e-j2

4/4

+e-j2

6/4

=0 X(3) = 1+ e-j2 =0 8-point DFT N=8 X(n) = {1,1,1,1,0,0,0,0}


N-1
3 /4

+e-j2

6/4

+e-j2

9/4

X(k) = x(n) e-j2


n=0

kn/N

k = 0,1,2..,N-1
7

X(k) = x(n) e-j2


n=0

kn/8

k = 0,1,2,3,4,5,6,7 X(k) = x(0)+x(1) e +x(5) e-j2


k5/8 -j2k/8

+x(2) e

-j2k2/8

+x(3) e-j2
k7/8 k3/8

k3/8

+x(4) e-j2

k4/8

+x(6) e-j2

k6/8

+x(7) e-j2

X(k) = 1+x(1) e-j2

k/8

+x(2) e-j2 +e-j2

k2/8

+x(3) e-j2

X(0) = 1+1+1+1 = 4 X(1) = 1+ e-j2 /8 +e-j2 = 1-2.414j X(2) = 1+ e-j2 =0 X(3) = 1+ e-j2 X(4) = 1+ e-j2 =0 X(5) = 1+ e-j2 X(6) = 1+ e-j2 =0 X(7) = 1+ e-j2
7/8 5 /8 3 /8 2 /4 2/8 3/8

+e-j2 +e-j2 +e-j2 +e-j2 +e-j2 +e-j2

4/4

+e-j2 +e-j2

6/4

6/8

9/8

= 1-0.414j
4 /8 8 /8

+e-j2

12/8

10/8

+e-j2

15/8

= 1+0.414j
6/8 12/8

+e-j2 +e-j2

18/8

14/8

21/8

= 1+2.414j

16point DFT N = 16 X(n) = {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0}


N-1

X(k) = x(n) e-j2


n=0

kn/N

k = 0,1,2..,N-1
15

X(k) = x(n) e-j2


n=0

kn/16

k = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 X(k) = 1+x(1) e X(1) = 1+ e-j2 X(2) = 1+ e-j2 X(3) = 1+ e-j2 X(4) = 1+ e-j2 =0 X(5) = 1+ e-j2 X(6) = 1+ e-j2 =0 X(7) = 1+ e-j2 X(8) = 1+ e-j2 =0 X(9) = 1+ e-j2 X(10) = 1+ e-j2
9 /16 7/16 5 /16 -j2k/16

+x(2) e +e-j2

-j2k2/16

+(3) e-j2

k3/16

X(0) = 1+1+1+1 = 4
/16

+e-j2

2/16

3/16

= 3.007-2.007j
2 /16

+e-j2 +e-j2 +e-j2 +e-j2

4/16

+e-j2 +e-j2

6/16

= 1-2.414j
3 /16 6/16 9/16

= 1.593-1.247j
4 /16 8 /16

+e-j2

12/16

10/16

+e-j2

15/16

= 0.833+0.167j
6/16

+e-j2 +e-j2

12/16

+e-j2 +e-j2

18/16

14/16

21/16

= 1.166-2.012j
8 /16

+e-j2 +e-j2

16 /16

+e-j2 +e-j2

24 /16

18 /16

27/16

= 0.407+0.593j
10 /16

+e-j2

20/16

+e-j2

30/16

= 1+0.414j

X(11) = 1+ e-j2

11 /16

+e-j2

22/16

+e-j2

33/16

= 0.833-0.167j X(12) = 1+ e-j2 =0 X(13) = 1+ e-j2 X(14) = 1+ e-j2 = 1+j X(15) = 1+ e-j2
15 /16 13 /16 12 /16

+e-j2

24/16

+e-j2

36/16

+e-j2

26/16

+e-j2

39/16

= -0.247+1.247j
14 /16

+e-j2 +e-j2

28/16

+e-j2 +e-j2

42/16

30/16

45/16

= 3.007+2.007j

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 3 2 1 0

0.5

1.5 angle of 4-point DFT

2.5

-1

-2

-3

0.5

1.5

2.5

magnitude of 8-point DFT 4 3 2 1 0

angle of 8-point DFT 2

-2

-4

magnitude of 16-point DFT 4 3 2 1 0

5 angle of 16-point DFT

10

15

-2

-4

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: Wp=0.2*pi, Ws=0.3*pi, As=50db, Ap=0.25 db

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: FIR filters are easy to represent as matrices of coefficients. Two-dimensional FIR filters are natural extensions of one-dimensional FIR filters. There are several well-known, reliable methods for FIR filter design. FIR filters are easy to implement. FIR filters can be designed to have linear phase, which helps prevent distortion. 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: Transforming a single one-dimensional window to create a two-dimensional window that is nearly circularly symmetric, by using a process similar to rotation Creating a rectangular, separable window from two one-dimensional windows, by computing their outer product

CODE: 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
Transform H(s) = (s+1)/(s2+5s+6) into a digital filter using: (a) Impulse Invariant Transformation (b) Bilinear Transformation

THEORY
Impulse Invariant Transformation 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) H(z) = (1-0.8966z-1)/(1-1.5595 z-1+0.66065 z-1)

Bilinear Transformation
In this technique the desired impulse response of the digital filter is obtained uniformly sampling the impulse response of the analog filter. H(s) = (s+1)/ (s2+5s+6) 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= c= d= 0.1000 1 1 1 5 6

r= p= k= p=

2.0000 -1.0000 -3.0000 -2.0000 [] 0.7408 0.8187

b = 1.0000 -0.8966 a = 1.0000 -1.5595 0.6065 b = 1.0000 -0.8966 a = 1.0000 -1.5595 0.6065 ****************************** Bilinear Transformation Method ****************************** c= d= T= 1 1 1 1 5 6

Fs = 1 b= a= 0.1500 0.1000 -0.0500 1.0000 0.2000 -0.0000

You might also like