0% found this document useful (0 votes)
63 views23 pages

1 Gggi: Experiment No:-1 AIM:-Write A Program To Plot The Following Functions

The document contains the aims and code for 10 experiments related to digital signal processing topics like discrete Fourier transforms, filters, and signal properties. Experiment 1 plots various common functions. Experiment 2 defines a function to compute the discrete-time Fourier transform of a signal and plots the magnitude and phase. Experiment 3 verifies properties of the DTFT like symmetry, time shifting, and modulation. Experiment 4 finds the convolution, cross-correlation, and auto-correlation of sequences. Experiment 5 calculates the discrete Fourier transform of a signal and plots the real, imaginary, magnitude, and phase components.

Uploaded by

Vishav Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views23 pages

1 Gggi: Experiment No:-1 AIM:-Write A Program To Plot The Following Functions

The document contains the aims and code for 10 experiments related to digital signal processing topics like discrete Fourier transforms, filters, and signal properties. Experiment 1 plots various common functions. Experiment 2 defines a function to compute the discrete-time Fourier transform of a signal and plots the magnitude and phase. Experiment 3 verifies properties of the DTFT like symmetry, time shifting, and modulation. Experiment 4 finds the convolution, cross-correlation, and auto-correlation of sequences. Experiment 5 calculates the discrete Fourier transform of a signal and plots the real, imaginary, magnitude, and phase components.

Uploaded by

Vishav Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 23

S.No.

NAME OF EXPERIMENTS
Write a program to plot the following functions:
(a) Impulse function (b)unit step function

(c)unit ramp function

(d)sinusoidal function (e)cosine function (f)exponential function.


Define a function to compute DTFT of a finite length signal. Plot the
magnitude & phase plots using subplots.

Verify the symmetry, time shifting, linearity & modulation properties of


DTFT with a function x(n)= (0.5)n u(n).

Write a program to find convolution, cross-correlation and auto-correlation


of sequences using in-built convolution and correlation functions.

Write a program to calculate DFT of signal x(n) & to plot its real, imaginary,
magnitude & phase plots

Write a program to verify the properties of DFT.

Write a program to plot real, imaginary, magnitude & phase part of


exponential function. x= exp(-0.1+0.3j)n

Write a program to covert an analog signal to a discrete signal and then


reconstruct the original signal.

Write a program to a BUTTERWORTH low pass filter.

10

Write a program to an ELLIPTICAL low pass filter.

EXPERIMENT NO:- 1
AIM:-Write a program to plot the following functions:
(A) Impulse function
(b) unit step function
(c) Unit ramp function
(d) sinusoidal function
(e) Cosine function
(f) exponential function
%%to plot impulse function.
x=-2:1:2;
y=[0 0 1 0 0];
subplot(2,3,1)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('impulse function')
%%to plot unit step function.
x=0:1:20;
y=ones(1,21);
subplot(2,3,2)
stem(x,y)

1
GGGI

xlabel('time')
ylabel('amplitude')
title('unit sample function')
%%to plot unit ramp function.
x=0:1:20;
subplot(2,3,3)
stem(x,x)
xlabel('time')
ylabel('amplitude')
title('unit ramp function')
%%to plot sinusoidal function.
x=0:0.1:10;
y=sin(x);
subplot(2,3,4)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('sinusoidal function')
%%to plot cosine function.
x=0:0.1:10;
y=cos(x);
subplot(2,3,5)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('cosine function')
%%to plot exponential function.
x=0:0.1:10;
y=exp(x);
subplot(2,3,6)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('exponential function')
OUTPUT:-

2
GGGI

impulse function

0.4
0.2

0.6
0.4

-1

0
time

sinusoidal function

10
time

15

20

cosine function

2.5

-0.5

amplitude

0
-0.5

5
time

10

-1

10
time

15

20

4
x 10 exponential function

0.5
amplitude

0.5

10
5

0.2

0
-2

amplitude

15
amplitude

0.6

unit ramp function

20

0.8
amplitude

amplitude

0.8

-1

unit sample function

1.5
1
0.5

5
time

10

5
time

10

FIGURE

EXPERIMENT NO:-2
AIM:- Define a function to compute DTFT of a finite length signal.Plot the magnitude
& phase plots using subplots.
w = (0:1:500)*pi/500
X= exp(j*w)./(exp(j*w)-0.5*ones(1,501)); %%%% x(n)= (0.5)n u(n)
subplot(2,2,1);
plot(w/pi,real(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('real-plot') %%%%To plot real-plot

subplot(2,2,2);
plot(w/pi,imag(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary-plot') %%%%To plot imaginary-plot
magX= abs(X)
phzX=angle(X)
subplot(2,2,3);
plot(w/pi,magX);grid;
xlabel('frequency')

3
GGGI

ylabel('amplitude')
title('magnitude-plot') %%%%To plot magnitude-plot

subplot(2,2,4);
plot(w/pi,phzX);grid;
xlabel('frequency')
ylabel('amplitude')
title('phase-plot') %%%%To plot phase-plot

OUTPUT:
real-plot

-0.2

1.5

0.5

0.2

0.4
0.6
frequency

0.8

-0.8

magnitude-plot

0.2

0.4
0.6
frequency

0.8

0.8

phase-plot

0
-0.2

1.5

amplitude

amplitude

-0.4
-0.6

0.5

imaginary-plot

amplitude

amplitude

-0.4
-0.6

0.2

0.4
0.6
frequency

0.8

-0.8

0.2

0.4
0.6
frequency

FIGURE

4
GGGI

EXPERIMENT NO:-3
%AIM:-Verify the symmetry,time shifting,linearity & modulation properties of
%
DTFT with a function x(n)= (0.5)n u(n).
%symmetric property
w = (0:1:500)*pi/500
X= exp(j*w)./(exp(j*w)-0.5*ones(1,501)); %%%% x(n)= (0.5)n u(n)
subplot(2,2,1);
plot(w/pi,real(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('real-plot') %%%%To plot real-plot of x(n)
subplot(2,2,2);
plot(w/pi,imag(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary-plot') %%%%To plot imaginary-plot of x(n)
Y= exp(-j*w)./(exp(-j*w)-0.5*ones(1,501)); %%%% x(n)= (0.5)n u(n)
subplot(2,2,3);
plot(w/pi,real(Y));grid;
xlabel('frequency')
ylabel('amplitude')
title('real-plot') %%%%Real-plot of complex conjugate of DTFT of x(n)
subplot(2,2,4);
plot(w/pi,imag(Y));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary-plot') %%%%Imaginary-plot of complex conjugate of DTFT of x(n)

5
GGGI

OUTPUT:
real-plot

-0.2

1.5

0.5

0.2

0.4
0.6
frequency

0.8

-0.8

real-plot

0.2

0.4
0.6
frequency

0.8

0.8

imaginary-plot

0.8
0.6

1.5

amplitude

amplitude

-0.4
-0.6

0.5

imaginary-plot

amplitude

amplitude

0.4
0.2

0.2

0.4
0.6
frequency

0.8

0.2

0.4
0.6
frequency

FIGURE

%%linearity property
n=0:10;
k=0:500;
w= k*pi/500;
x1=rand(1,11)
x2=rand(1,11)
a=2;b=3;
y1= a*x1+b*x2;
Y1=y1*exp(-j*(pi/500)*n'*k);
subplot(2,2,1);
plot(w/pi,real(Y1)); grid;
xlabel('frequency')
ylabel('amplitude')
title('real-plot of Y1') %%%%To plot real-plot of Y1
subplot(2,2,2);
plot(w/pi,imag(Y1)) ; grid;

6
GGGI

xlabel('frequency')
ylabel('amplitude')
title('imaginary-plot of Y1') %%%%To plot imaginary-plot of Y1
X1=x1*exp(-j*(pi/500)*n'*k);
X2=x2*exp(-j*(pi/500)*n'*k);
Y2=a*X1+b*X2;
subplot(2,2,3);
plot(w/pi,real(Y2)) ; grid;
xlabel('frequency')
ylabel('amplitude')
title('real-plot of Y2') %%%%To plot real-plot of Y2
subplot(2,2,4);
plot(w/pi,imag(Y2)) ; grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary-plot of Y2') %%%%To plot imaginary-plot of Y2

7
GGGI

OUTPUT:

real-plot of Y1

40

20

amplitude

amplitude

30

10

0.2

0.4
0.6
frequency

0.8

-30

real-plot of Y2

40

0.2

0.4
0.6
frequency

0.8

0.8

imaginary-plot of Y2

20

amplitude

amplitude

10

30

10

-10
-20

0
-10

-10
-20

0
-10

imaginary-plot of Y1

10

0.2

0.4
0.6
frequency

0.8

-30

0.2

0.4
0.6
frequency

FIGURE

%time shifting property


n=-5:5;
x1= (0.5).^n;
k=-200:200;
w= k*pi/100;
X1=x1*exp(-j*(pi/100)*n'*k);
subplot(2,2,1);
plot(w/pi,abs(X1)) ; grid;
xlabel('frequency')
ylabel('amplitude')
title('magnitude-plot of X1') %%%%To plot magnitude-plot of X1
subplot(2,2,2);
plot(w/pi,angle(X1));grid;

8
GGGI

xlabel('frequency')
ylabel('amplitude')
title('phase-plot of X1')

%%%%To plot phase-plot of X1

x2=x1
m=n+2;
X2=x2*exp(-j*(pi/100)*m'*k);
subplot(2,2,3);
plot(w/pi,abs(X2));grid;
xlabel('frequency')
ylabel('amplitude')
title('magnitude-plot of X2') %%%%To plot magnitude-plot of X2
subplot(2,2,4);
plot(w/pi,angle(X2));grid;
xlabel('frequency')
ylabel('amplitude')
title('phase-plot of X2') %%%%To plot phase-plot of X2

OUTPUT:

9
GGGI

magnitude-plot of X1

70

50

amplitude

amplitude

60

40

-1

0
frequency

-4
-2

magnitude-plot of X2

70

0
frequency

phase-plot of X2

50

amplitude

amplitude

-1

60

40

0
-2

30
20
-2

0
-2

30
20
-2

phase-plot of X1

-1

0
frequency

-4
-2

-1

0
frequency

FIGURE

%modulating property
n=0:100
k=-100:100
w=k*pi/100
x1= cos(n*pi/2)
X1=x1*exp(-j*(pi/100)*n'*k);
subplot(2,2,1);
plot(w/pi,abs(X1));grid;
xlabel('frequency')
ylabel('amplitude')
title('magnitude-plot of X1') %%%%To plot magnitude-plot of X1
subplot(2,2,2);
plot(w/pi,angle(X1));grid;
xlabel('frequency')
ylabel('amplitude')
title('phase-plot of X1') %%%%To plot phase-plot of X1

10
GGGI

x2=x1.*exp(-j*n*pi/4)
X2=x2*exp(-j*(pi/100)*n'*k);
subplot(2,2,3);
plot(w/pi,abs(X2));grid
xlabel('frequency')
ylabel('amplitude')
title('magnitude-plot of X2') %%%%To plot magnitude-plot of X2
subplot(2,2,4);
plot(w/pi,angle(X2));grid
xlabel('frequency')
ylabel('amplitude')
title('phase-plot of X2')

%%%%To plot phase-

OUTPUT:
60

magnitude-plot of X1

40

amplitude

amplitude

50

30
20

60

-0.5

0
frequency

0.5

-2
-1

magnitude-plot of X2

0
frequency

0.5

0.5

phase-plot of X2

40

amplitude

amplitude

-0.5

50

30
20

0
-1

10
0
-1

0
-1

10
0
-1

phase-plot of X1

-0.5

0
frequency

0.5

-2
-1

-0.5

0
frequency

FIGURE

11
GGGI

EXPERIMENT NO:-4
%AIM:-Write a program to find convolution, cross-correlation and auto-correlation of
%sequences using in-built convolution and correlation functions.
x=[1 2 3 4];%% input sequence
h=[2 3 4 5];%% impulse response
l1=length(x);
l2=length(h);
n=0:1:l1+l2-2;
n1=0:1:l1-1;
n2=0:1:l2-1;
subplot(2,3,1);
stem(n1,x); grid;
xlabel('n');ylabel('x(n)');
title('input sequence');%%to plot input sequence
subplot(2,3,2);
stem(n2,h); grid;
xlabel('n');ylabel('h(n)');
title('impulse response sequence');%% to plot impulse response
% convolution
y=conv(x,h);
subplot(2,3,3);
stem(n,y);grid;
xlabel('n');ylabel('x(n)');
title('output sequence'); %% to plot convolution of two sequences
%auto-correlation
n3= -(l1-1):(l1-1)
y1=xcorr(x,x);
subplot(2,3,4);
stem(n3,y1);grid;
xlabel('n');ylabel('x(n)');
title('output sequence'); %% to plot auto-correlation of a sequence
%cross-correlation
n4= -(l1-1):(l2-1)
y2=xcorr2(x,h);
subplot(2,3,5);
stem(n4,y2);grid;
xlabel('n');ylabel('x(n)');
title('output sequence'); %% to plot cross-correlation of two sequences

12
GGGI

OUTPUT:
input sequence

3
2

output sequence

output sequence

30

20
x(n)

15
10

20
10

5
0
-4

40

25

20
10

30

x(n)

30
x(n)

h(n)

x(n)

output sequence

40

impulse response sequence

-2

0
n

0
-4

-2

0
n

FIGURE

Experiment No. 5
AIM: Write a program to calculate DFT of signal x(n) & to plot its real, imaginary,
magnitude & phase plots
n= 60;
x= [1 1 1];
X=fft(x,n);
subplot(3,2,1)
stem(x);grid;
xlabel('frequency')
ylabel('amplitude')
title('signal x(n)')%%plot of sequence x(n))
subplot(3,2,2)

13
GGGI

stem(X);grid;
xlabel('frequency')
ylabel('amplitude')
title('DFT of signal x(n)') %%plot of DFT(x(n))
subplot(3,2,3)
stem(real(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('real part of X')

%%plot of real part of DFT(x(n))

subplot(3,2,4)
stem(imag(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary part of X')%%plot of imaginary part of DFT(x(n))
subplot(3,2,5)
stem(abs(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('magnitude part of X') %%plot of magnitude part of DFT(x(n))
subplot(3,2,6)
stem(angle(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('phase part of X')%%plot of phase part of DFT(x(n))
OUTPUT:

signal x(n)

DFT of signal x(n)

amplitude

amplitude

1
0.5

1.2

1.4

1.6

1.8

2
2.2
frequency
real part of X

2.4

2.6

2.8

amplitude

amplitude

10

20

30
40
frequency
imaginary part of X

10

20

30
frequency
phase part of X

10

20

30
frequency

50

60

40

50

60

40

50

60

0
0

10

20

30
40
frequency
magnitude part of X

50

0
-1
-2

60

2
1

amplitude

amplitude

1
0

-1
-2

-1

10

20

30
frequency

40

50

0
-1
-2

60

FIGURE

14
GGGI

Experiment No. 6
AIM: Write a program to verify the properties of DFT.
Linearity property
n=0:10;
x1=(0.5).^n;
x2=(0.7).^n;
a=5; b=7;
x3= a*x1+b*x2;
X3=fft(x3);
subplot(2,2,1)
stem(n,real(X3));grid;
xlabel('frequency')
ylabel('amplitude')
title('real part of X3') %% plot of real part of DFT(ax1+bx2)
subplot(2,2,2)
stem(n,imag(X3));grid;
xlabel('frequencACy')
ylabel('amplitude')
title('imaginary part of X3')%% plot of imaginary part of DFT(ax1+bx2)
X1=fft(x1);
X2=fft(x2);
X4= a*X1+b*X2
subplot(2,2,3)
stem(n,real(X4));grid;
xlabel('frequency')
ylabel('amplitude')
title('real part of X4')%%plot of real part of (a*DFT(x1)+b*DFT(x2))
subplot(2,2,4)
stem(n,imag(X4));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary part of X4')%%plot of imaginary part of

a*DFT(x1)+b*DFT(x2))

OUTPUT:

15
GGGI

real part of X3

40

10
amplitude

amplitude

30
20
10
0

4
6
frequency

0
-5

-15

10

real part of X4

4
6
frequencACy

10

10

imaginary part of X4

15
10
amplitude

30
amplitude

-10

40

20
10
0

imaginary part of X3

15

5
0
-5
-10

4
6
frequency

10

-15

4
6
frequency

FIGURE

Symmetry property:
n=0:10;
x=(0.5).^n;
X=fft(x);
subplot(2,2,1)
stem(n,real(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('real part of X') %% plot of real part of DFT(X)
subplot(2,2,2)
stem(n,imag(X));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary part of X')%% plot of imaginary part of DFT(X)
y=x(mod(-n,11)+1);

16
GGGI

xe=(x+y)/2;
xo=(x-y)/2;

%% even component
%% odd component

XE=fft(xe);
XO=fft(xo);

%% dft of even component


%% dft of odd component

subplot(2,2,3)
stem(n,real(XE));grid;
xlabel('frequency')
ylabel('amplitude')
title('real part of XE') %% plot of real part of DFT(XE)
subplot(2,2,4)
stem(n,imag(XO));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary part of XO')%% plot of imaginary part of DFT(XO)

Experiment No. 7
AIM: Write a program to plot real, imaginary, magnitude & phase part of exponential
function. x= exp(-0.1+0.3j)n
n= -10:10;
x= exp((-0.1+0.3j)*n); %% exponential function
subplot(2,2,1)
stem(n,real(x));grid;
xlabel('frequency')
ylabel('amplitude')
title('real part of x(n)') %%plot of real part of x(n)
subplot(2,2,2)
stem(n,imag(x));grid;
xlabel('frequency')
ylabel('amplitude')
title('imaginary part of x(n)')%%plot of imaginary part of x(n)
subplot(2,2,3)
stem(n,abs(x));grid;
xlabel('frequency')
ylabel('amplitude')
title('magnitude part of x(n)') %%plot of magnitude part of x(n)
subplot(2,2,4)
stem(n,angle(x));grid;
xlabel('frequency')
ylabel('amplitude')
title('phase part of x(n)')%%plot of phase part of x(n)

17
GGGI

OUTPUT:
real part of x(n)

1
0.5
amplitude

amplitude

1
0
-1
-2
-3
-10

0
-0.5
-1
-1.5

-5

0
frequency

-2
-10

10

magnitude part of x(n)

2.5

1.5
1
0.5
0
-10

-5

0
frequency

10

10

phase part of x(n)

amplitude

amplitude

imaginary part of x(n)

0
-1
-2

-5

0
frequency

10

-3
-10

-5

0
frequency

FIGURE

Experiment No. 8
18
GGGI

AIM: Write a program to convert a continuous time signal to a discrete signal and
then reconstruct the original signal.

Program:
t=-0.005:0.00005:0.005;
x=exp(-1000*abs(t));
subplot(2,2,1)
plot(t,x);
xlabel('t');ylabel('amplitude');
title('analog signal'); %% To plot continuous time signal
n=-25:1:25;
T=1/5000;
z=exp(-1000*abs(n*T));
subplot(2,2,2)
stem(n*T,z);
xlabel('n');ylabel('amplitude');
title('sampled signal');
%%To plot discrete time signal
xi=-0.005:0.00005:0.005;
yi=spline(T*n,z,xi);
subplot(2,2,3)
plot(xi,yi);
xlabel('t');ylabel('amplitude');
title('reconstructed signal'); %%To plot reconstructed signal

OUTPUT:

19
GGGI

analog signal

1
0.8
amplitude

amplitude

0.8
0.6
0.4
0.2
0
-5

sampled signal

0.6
0.4
0.2

0
t

0
-5

5
-3

reconst. signal

x 10

0
n

5
-3

x 10

amplitude

0.8
0.6
0.4
0.2
0
-5

0
t

5
-3

x 10

FIGURE

Experiment No. 9
AIM: Write a program to a BUTTERWORTH low pass filter.

Program:
pa=4;
sa=10;
fp=400;
fs=800;
f=4000;
fp1=2*3.14*fp/f;
fs1=2*3.14*fs/f;

%PASSBAND
%STOPBAND
%PASSBAND
%STOPBAND
%SAMPLING
%PASSBAND
%STOPBAND

ATTENUATION
ATTENUATION
FREQUENCY
FREQUENCY
FREQUENCY
EDGE FREQUENCY
EDGE FREQUENCY

[N,Wn]=buttord(fp1,fs1,pa,sa); % N : ORDER & WN : NATURAL FREQUENCY


[B,A]=butter(N,Wn);
%% filter co-efficients

20
GGGI

[H,W]=freqz(B,A,N);
w1=0:0.01:pi;
[H]=freqz(B,A,w1);
z=abs(H);
x=angle(H);
subplot(1,2,1);
plot(w1,z);
xlabel('FREQUENCY');
ylabel('MAGNITUDE');
title('MAGNOITUDE VS FREQUENCY'); %%To plot magnitude
subplot(1,2,2);
plot(w1,x);
xlabel('FREQUENCY');label('PHASE ANGLE');
title('PHASE ANGLE VS FREQUENCY'); %%To plot phase

OUTPUT:

MAGNOITUDE VS FREQUENCY

PHASE ANGLE VS FREQUENCY

0.9

0.8
2

0.6

PHASE ANGLE

MAGNITUDE

0.7

0.5
0.4

-1

0.3
-2
0.2
-3

0.1
0

2
FREQUENCY

-4

2
FREQUENCY

21
GGGI

FIGURE

Experiment No. 10
AIM: Write a program to an ELLIPTICAL low pass filter.

Program:
pa=1;
%PASSBAND ATTENUATION
sa=15;
%STOPBAND ATTENUATION
fp=.2;
%PASSBAND FREQUENCY
fs=.3;
%STOPBAND FREQUENCY
[N,Wn]=ellipord(fp,fs,pa,sa); %N is ORDER & WN is NATURAL FREQUENCY
[B,A]=ellip(N,pa,sa,Wn);
%% filter co-efficients
[H,W]=freqz(B,A,N);
w1=0:0.01:pi;
[H]=freqz(B,A,w1);
z=abs(H);
x=angle(H);
subplot(1,2,1);
plot(w1,z);
xlabel('FREQUENCY');
ylabel('MAGNITUDE');
title('MAGNOITUDE VS FREQUENCY');

%%To plot magnitude

subplot(1,2,2);
plot(w1,x);
xlabel('FREQUENCY');
ylabel('PHASE ANGLE');
title('PHASE ANGLE VS FREQUENCY');

%%To plot phase

OUTPUT:

22
GGGI

MAGNOITUDE VS FREQUENCY

PHASE ANGLE VS FREQUENCY

0.9

0.8
2

0.6

PHASE ANGLE

MAGNITUDE

0.7

0.5
0.4

-1

0.3
-2
0.2
-3

0.1
0

2
FREQUENCY

-4

2
FREQUENCY

FIGURE

23
GGGI

You might also like