Digital Signal Processing Lab: Vishavjit Singh CSE-1 (6 Sem) 0581322707
Digital Signal Processing Lab: Vishavjit Singh CSE-1 (6 Sem) 0581322707
VISHAVJIT SINGH
CSE-1(6TH SEM)
0581322707 (053)
EXPERIMENT: 1
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.
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 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
OUTPUT:
EXPERIMENT: 3
OUTPUT:
EXPERIMENT: 4
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
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
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
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
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
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
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
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=
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
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