0% found this document useful (0 votes)
260 views22 pages

Digital Signal Processing Lab: Vishavjit Singh CSE-1 (6 Sem) 0581322707

This document contains details of experiments conducted using MATLAB for digital signal processing. It includes experiments to generate basic discrete and continuous time signals like unit step, unit sample, ramp, exponential, sine and cosine signals. Other experiments include determining the impulse response of a linear time-invariant system, performing matrix operations like addition, subtraction and multiplication on user-defined matrices, and implementing the discrete Fourier transform and its inverse on sequences. The document provides MATLAB code and output for each experiment.

Uploaded by

rsdelhi123
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
260 views22 pages

Digital Signal Processing Lab: Vishavjit Singh CSE-1 (6 Sem) 0581322707

This document contains details of experiments conducted using MATLAB for digital signal processing. It includes experiments to generate basic discrete and continuous time signals like unit step, unit sample, ramp, exponential, sine and cosine signals. Other experiments include determining the impulse response of a linear time-invariant system, performing matrix operations like addition, subtraction and multiplication on user-defined matrices, and implementing the discrete Fourier transform and its inverse on sequences. The document provides MATLAB code and output for each experiment.

Uploaded by

rsdelhi123
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 22

DIGITAL SIGNAL PROCESSING LAB

VISHAVJIT SINGH
CSE-1(6TH SEM)
0581322707 (053)
EXPERIMENT: 1

AIM:- Introduction to MATLAB/C


MATLAB is a high-performance language for technical computing. It integrates computation,
visualization, and programming in an easy-to-use environment where problems and solutions
are expressed in familiar mathematical notation. Typical uses include

 Math and computation


 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an array that does not require
dimensioning. This allows you to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program in
a scalar noninteractive language such as C or Fortran.

The name MATLAB stands for matrix laboratory. MATLAB has evolved over a period of years
with input from many users. In university environments, it is the standard instructional tool for
introductory and advanced courses in mathematics, engineering, and science. In industry,
MATLAB is the tool of choice for high-productivity research, development, and analysis.

The MATLAB system consists of five main parts:

Development Environment: This is the set of tools and facilities that help you use MATLAB
functions and files. Many of these tools are graphical user interfaces. It includes the MATLAB
desktop and Command Window, a command history, an editor and debugger, and browsers for
viewing help, the workspace, files, and the search path.

The MATLAB Mathematical Function Library: This is a vast collection of computational


algorithms ranging from elementary functions, like sum, sine, cosine, and complex arithmetic,
to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and
fast Fourier transforms.

The MATLAB Language: This is a high-level matrix/array language with control flow
statements, functions, data structures, input/output, and object-oriented programming features. It
allows both "programming in the small" to rapidly create quick and dirty throw-away programs,
and "programming in the large" to create large and complex application programs.
Graphics: MATLAB has extensive facilities for displaying vectors and matrices as graphs, as
well as annotating and printing these graphs. It includes high-level functions for two-
dimensional and three-dimensional data visualization, image processing, animation, and
presentation graphics. It also includes low-level functions that allow you to fully customize the
appearance of graphics as well as to build complete graphical user interfaces on your MATLAB
applications.

The MATLAB Application Program Interface (API): This is a library that allows you to
write C and Fortran programs that interact with MATLAB. It includes facilities for calling
routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and
for reading and writing MAT-files.
EXPERIMENT: 2

AIM:- Generate the following basic signals (discrete) using MATLAB

(i) Unit Step Signal


(ii) Unit Sample Signal
(iii) Unit Ramp Sequence
(iv) Exponential Sequence
(v) Sine Sequence
(vi) Cosine Sequence

(i) Unit Step Signal


>> n = -4:1:4;
>> y = [zeros(1,4) ones(1,5)]
>> subplot(3,2,1)
>> stem(n,y)
>> title('Unit Step Signal')
>> xlabel('time')
>> ylabel('y')

(ii) Unit Sample Signal


>> n = -4:1:4;
>> y = [zeros(1,4) ones(1,1) zeros(1,4)]
>> subplot(3,2,2)
>> stem(n,y)
>> title('Unit Sample Signal')
>> xlabel('time')
>> ylabel('y')

(iii) Unit Ramp Sequence


>> n = 0:0.2:6;
>> subplot(3,2,3)
>> stem(n,n)
>> title('Unit Ramp Sequence')
>> xlabel('time')
>> ylabel('y')

(iv) Exponential Sequence


>> n = 0:0.2:6;
>> y = exp(n);
>> subplot(3,2,4)
>> stem(n,y)
>> title('Exponential Sequence')
>> xlabel('time')
>> ylabel('y')
(v) Sine Sequence
>> n = 0:0.2:2*pi;
>> y = sin(2*n);
>> subplot(3,2,5)
>> stem(n,y)
>> title('Sine Sequence ')
>> xlabel('time')
>> ylabel('y')

(vi) Cosine Sequence


>> n = 0:0.2:2*pi;
>> y = cos(2*n);
>> subplot(3,2,6)
>> stem(n,y)
>> title('Cosine Sequence ')
>> xlabel('time')
>> ylabel('y')

OUTPUT:
EXPERIMENT: 3

AIM:- Generate the following basic signals (continuous) using MATLAB

(i) Unit Step Signal


(ii) Unit Sample Signal
(iii) Unit Ramp Sequence
(iv) Exponential Sequence
(v) Sine Sequence
(vi) Cosine Sequence

(i) Unit Step Signal


>> n = -4:0.01:4;
>> y = [zeros(1,400) ones(1,401)]
>> subplot(3,2,1)
>> plot(n,y)
>> title('Unit Step Signal')
>> xlabel('time')
>> ylabel('y')

(ii) Unit Sample Signal


>> n = -4:0.01:4;
>> y = [zeros(1,400) ones(1,1) zeros(1,400)]
>> subplot(3,2,2)
>> plot(n,y)
>> title('Unit Sample Signal')
>> xlabel('time')
>> ylabel('y')

(iii) Unit Ramp Sequence


>> n = 0:0.01:6;
>> subplot(3,2,3)
>> plot(n,n)
>> title('Unit Ramp Sequence')
>> xlabel('time')
>> ylabel('y')

(iv) Exponential Sequence


>> n = 0:0.01:6;
>> y = exp(n);
>> subplot(3,2,4)
>> plot(n,y)
>> title('Exponential Sequence')
>> xlabel('time')
>> ylabel('y')
(v) Sine Sequence
>> n = 0:0.01:2*pi;
>> y = sin(2*n);
>> subplot(3,2,5)
>> plot(n,y)
>> title('Sine Sequence ')
>> xlabel('time')
>> ylabel('y')

(vi) Cosine Sequence


>> n = 0:0.01:2*pi;
>> y = cos(2*n);
>> subplot(3,2,6)
>> plot(n,y)
>> title('Cosine Sequence ')
>> xlabel('time')
>> ylabel('y')

OUTPUT:
EXPERIMENT: 4

AIM:- Determine the first 41 samples of the impulse response samples


of the casual LTI system defined by
y(n) + 0.7y(n-1) – 0.45y(n-2) – 0.6y(n-3) = 0.8x(n) – 0.44x(n-1) + 0.36x(n-2) + 0.02 x(n-3)

SOLUTION:
y(n) + 0.7y(n-1) – 0.45y(n-2) – 0.6y(n-3) = 0.8x(n) – 0.44x(n-1) + 0.36x(n-2) + 0.02 x(n-3)
Taking Z – Transform on both the sides
Y(Z) + 0.7 z-1 Y(Z) - 0.45 z-2 Y(Z) - 0.6 z-3 Y(Z) = 0.8 X(Z) – 0.44 z-1 X(Z) + 0.36 z-2 X(Z)
+ 0.02 z-3 X(Z)
-1 -2 -3
H(Z) = Y(Z) = 1 + 0.7 z - 0.45 z - 0.6 z .
X(Z) 0.8 - 0.44 z-1 + 0.36 z-2 + 0.02 z-3

MATLAB CODE:
>> y = [1, 0.7, -0.45, -0.6];
>> x = [0.8, -0.44, 0.36, 0.02];
>> stepz(x, y, 41);
>> impz(x, y, 41);

OUTPUT:
EXPERIMENT: 5

AIM:- To perform addition, subtraction and multiplication of two


matrices of size m x n, where m and n are given by the user.

MATLAB CODE:
>> A = [1, 2, 3;
4, 5, 6;
7, 8, 9];

>> B = [9, 8, 7;
6, 5, 4;
3, 2, 1];

>> A+B
ans =
10 10 10
10 10 10
10 10 10

>> A-B
ans =
-8 -6 -4
-2 0 2
4 6 8

>> A*B
ans =
30 24 18
84 69 54
138 114 90
EXPERIMENT: 5

AIM:- To perform addition, subtraction and multiplication of two


matrices of size m x n, where m and n are given by the user.

MATLAB CODE:
clc; close all; clear all;
m=input('Enter the number of rows of first matrix: ');
n=input('Enter the number of columns of first matrix: ');
A=zeros(m,n);
disp('Enter values of first matrix row-column wise: ');
for i=1:1:m
for j=1:1:n
A(i,j)=input('Enter value: ');
end
end

p=input('\nEnter the number of rows of second matrix: ');


q=input('Enter the number of columns of second matrix: ');
B=zeros(m,n);
disp('Enter values of second matrix row-column wise: ');
for i=1:1:p
for j=1:1:q
B(i,j)=input('Enter value: ');
end
end

for i=1:1:p
for j=1:1:q
C(i,j) = A(i,j)+ B(i,j);
end
end

for i=1:1:m
for j=1:1:n
D(i,j) = A(i,j)- B(i,j);
end
end

E=zeros(m,q);
for i=1:1:m
for j=1:1:q
E(i,j)=A(i,:)*B(:,j);
end
end
disp('Addition');C
disp('Substraction');D
disp('Multiplication');E

OUTPUT:
Enter the number of rows of first matrix: 3
Enter the number of columns of first matrix: 3
Enter values of first matrix row-column wise:
Enter value: 1
Enter value: 2
Enter value: 3
Enter value: 4
Enter value: 5
Enter value: 6
Enter value: 7
Enter value: 8
Enter value: 9

Enter the number of rows of second matrix: 3


Enter the number of columns of second matrix: 3
Enter values of second matrix row-column wise:
Enter value: 9
Enter value: 8
Enter value: 7
Enter value: 6
Enter value: 5
Enter value: 4
Enter value: 3
Enter value: 2
Enter value: 1

Addition
C = 10 10 10
10 10 10
10 10 10

Substraction
D = -8 -6 -4
-2 0 2
4 6 8

Multiplication
E = 30 24 18
84 69 54
138 114 90
EXPERIMENT: 6

AIM:- Write a matlab program to perform Discrete Fourier Transform.

MATLAB CODE:
clc;
close all;
clear all;
x=input('Enter x(n):');
N=length(x);
m=0:1:N-1;
subplot(2,2,1),stem(m,x);
title('Input Sequence x(n)');
xlabel('n-->');
ylabel('x(n)-->');
X=zeros( 1,N);
for k=0:1:N-1
for n=0:1:N-1
X(k+ 1)=X(k+ 1)+(x(n+ 1)*(cos(2*pi*n*k/N)-(sin(2*pi*n*k/N))*i));
end
end
disp('DFT of x(n) is :');
disp(X);
subplot(2,2,3);
stem(m,real(X));
title('Real Part of X(k)');
ylabel('real X(k)-->');
subplot(2,2,4);
stem(m,imag(X));
title('Imaginary Part of X(k)');
ylabel('imag X(k)-->');
OUTPUT:
Enter x(n):[1, 2, 3, 4, 5]
DFT of x(n) is :
15.0000 -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 - 3.4410i
EXPERIMENT: 7

AIM:- Write a matlab program to perform Inverse Discrete Fourier


Transform.

MATLAB CODE:
clc;
clear all;
X=input('Enter X(k): ');
N=length(X);
m=0:1:N-1;
subplot(2,2,1);
stem(m,real(X));
title('Real part of X(k)');
ylabel('real X(k) -->');
subplot(2,2,2);
stem(m,imag(X));
title('Imaginary part of X(k)');
ylabel('imag X(k) -->');
x=zeros( 1,N);
for n=0:1:N-1
x(n+1)=0;
for k=0:1:N-1
x(n+1)=x(n+1)+(X(k+1)*(cos(2*pi*n*k/N)+i*sin(2*pi*n*k/N)));
end
end
x=x/N;
disp('IDFT of x(n) is :');
disp(x);
subplot(2,2,[3,4]),stem(m,x);
title('Output sequence x(n)');
xlabel('n -->');
ylabel('x(n) -->');
OUTPUT:
Enter X(k): [(-1.5 + 2.56i) (-3.76 + 2.65i) (0 + 0.0i) (-1.5 - 2.56i) (-3.76 - 2.46i) ]
IDFT of x(n) is :
-0.5221 + 0.9380i -1.7950 + 1.1143i -0.6358 + 0.6526i -0.4083 + 1.2233i 0.7509 + 0.7616i
EXPERIMENT: 8

AIM:- Write a matlab program to compute cross-correlation.

MATLAB CODE:
clear all;
clc;
y=input('Input the first signal: ');
m=length(y);
n=0:1:m-1;
subplot(2,2,1),stem(n,y);
title('First input signal');
xlabel('n -->'),ylabel('Amplitude -->');
z=input('Input the second signal: ');
m=length(z);
n=0:1:m-1;
subplot(2,2,2),stem(n,z);
title('Second input signal');
xlabel('n -->'),ylabel('Amplitude -->');
p=xcorr(y,z );
disp('The output signal is');p
j=0:1:length(p)-1;
subplot(2,2,[3,4]),stem(j,p);
title('Cross-correlation');
xlabel('n -->'),ylabel('Amplitude -->');
OUTPUT:
Input the first signal: [1 2 3 4]
Input the second signal: [4 3 2 1]
The output signal is

p=

1.0000 4.0000 10.0000 20.0000 25.0000 24.0000 16.0000


EXPERIMENT: 9

AIM:- Write a matlab program to design Butterworth low-pass IIR


Filter.

ALGORITHM:
1. Get the passband and stopband ripples.
2. Get the passband and stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude and the phase responses.

MATLAB CODE:
clear all; close all;
clc;
format long
rp = input('Enter the passband ripple: ');
rs = input('Enter the stopband ripple: ');
wp = input('Enter the passband frequency: ');
ws = input('Enter the passband frequency: ');
fs = input('Enter the sampling frequency: ');
w1 = 2*wp/fs; w2=2*ws/fs;
[n,wn] = buttord(w1,w2,rp,rs);
[b,a] = butter(n,wn);
w=0:.01:pi;
[h,om] = freqz(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1); plot(om/pi,m);
xlabel('Normalized frequency -->');
ylabel('Gain in dB -->');
subplot(2,1,2); plot(om/pi,an);
xlabel('Normalized frequency -->');
ylabel('Phase in radians -->');
OUTPUT:
Enter the passband ripple: 0.5
Enter the stopband ripple: 50
Enter the passband frequency: 1200
Enter the passband frequency: 2400
Enter the sampling frequency: 10000
EXPERIMENT: 10

AIM:- Write a matlab program to design Chebyshev type-1 low-pass


IIR Filter.

ALGORITHM:
1. Get the passband and stopband ripples.
2. Get the passband and stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude and the phase responses.

MATLAB CODE:
clear all; close all;
clc;
format long
rp = input('Enter the passband ripple: ');
rs = input('Enter the stopband ripple: ');
wp = input('Enter the passband frequency: ');
ws = input('Enter the passband frequency: ');
fs = input('Enter the sampling frequency: ');
w1 = 2*wp/fs; w2=2*ws/fs;
[n,wn] = cheb1ord(w1,w2,rp,rs);
[b,a] = cheby1(n,rp,wn);
w=0:.01:pi;
[h,om] = freqz(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1); plot(om/pi,m);
xlabel('Normalized frequency -->');
ylabel('Gain in dB -->');
subplot(2,1,2); plot(om/pi,an);
xlabel('Normalized frequency -->');
ylabel('Phase in radians -->');
OUTPUT:
Enter the passband ripple: 0.2
Enter the stopband ripple: 45
Enter the passband frequency: 1300
Enter the passband frequency: 1500
Enter the sampling frequency: 10000

You might also like