DSP Lab Experiments BEC502
DSP Lab Experiments BEC502
1
Elementary Discrete-Time Signals
Theory: Write relevant theory with expressions and sketches for each signal.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Programs:
c) Exponential sequence
i. Real exponential sequence
% Generation of a real exponential sequence
n=0:40;
K = 0.2;
% Exponential sequence for a>1
a1 = 1.2;
x1 = K*a1.^n;
subplot(2,2,1);
stem(n,x1);
title('Exponential Sequence (a>1)');
xlabel('n'); ylabel('Amplitude');
d) Sinusoidal sequence
n=-10:10;
A=1.2;
f=0.1;
x=A*cos(2*pi*f*n);
stem(n,x);
title('Sinusoidal Sequence');
xlabel('n');
ylabel('Amplitude');
e) Random sequence
n=-10:10;
x=rand(size(n))*20-10;
stem(n,x);
title('Random Sequence');
xlabel('n');
ylabel('Amplitude');
Output:
e) Random sequence
Result:
The programs to generate elementary discrete-signal signals were written and the
signals were plotted successfully.
Experiment No. 2
Simple Operations on Discrete-Time Signals
Theory: Write relevant theory with expressions and examples for each operation.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Programs:
a) Signal addition
n=-5:5;
x1=[1 -3 2 -4 2 1 -3 5 1 -3 -4];
x2=[2 3 4 3 1 0 3 -2 1 2 3];
% Perform signal addition
y=x1+x2;
% Plot Signal x1
subplot(3,1,1);
stem(n,x1);
title('Signal x1');
xlabel('n');ylabel('Amplitude');
% Plot Signal x2
subplot(3,1,2);
stem(n,x2);
title('Signal x2');
xlabel('n');ylabel('Amplitude');
% Plot the output signal
subplot(3,1,3);
stem(n,y);
title('Signal y=x1+x2');
xlabel('n');ylabel('Amplitude');
b) Signal multiplication
n=-5:5;
x1=[1 -3 2 -4 2 1 -3 5 1 -3 -4];
x2=[2 3 4 3 1 0 3 -2 1 2 3];
% Perform signal multiplication
y=x1.*x2;
% Plot Signal x1
subplot(3,1,1);
stem(n,x1);
title('Signal x1');
xlabel('n');ylabel('Amplitude');
% Plot Signal x2
subplot(3,1,2);
stem(n,x2);
title('Signal x2');
xlabel('n');ylabel('Amplitude');
% Plot the output signal
subplot(3,1,3);
stem(n,y);
title('Signal y=x1.*x2');
xlabel('n');ylabel('Amplitude');
c) Scaling
n=-10:10;
f=0.1;
A=3; %scaling factor
x=1.5*sin(2*pi*f*n);
y=A*x;
% Plot the input signal x
subplot(2,1,1);
stem(n,x);
title('Signal x');
xlabel('n');ylabel('Amplitude');
% Plot the output signal y
subplot(2,1,2);
stem(n,y);
title('Signal y=A*x');
xlabel('n');ylabel('Amplitude');
d) Shifting
n=-5:5;
% Input signal
x=[1 -3 2 -4 2 1 -3 5 1 -3 -4];
k=3; % Shifting units of time
%Generate time delay by k units
x_delayed=[zeros(1,k) x(1:end-k)];
%Generate time advance by k units
x_advanced=[x(k+1:end) zeros(1,k)];
% Plot the input signal x
subplot(3,1,1);
stem(n,x);
title('Signal x');
xlabel('n');ylabel('Amplitude');
% Plot the delayed signal
subplot(3,1,2);
stem(n,x_delayed);
title('Signal Delayed by k=3');
xlabel('n');ylabel('Amplitude');
% Plot the advanced signal
subplot(3,1,3);
stem(n,x_advanced);
title('Signal Advanced by k=3');
xlabel('n');ylabel('Amplitude');
e) Folding
n=-5:5;
% Input signal
x=[1 -3 2 -4 2 1 -3 5 1 -3 -4];
% Perform signal folding
y=fliplr(x);
% Plot the input signal x
subplot(2,1,1);
stem(n,x);
title('Signal x(n)');
xlabel('n');ylabel('Amplitude');
% Plot the folded signal y
subplot(2,1,2);
stem(n,y);
title('Signal y=x(-n)');
xlabel('n');ylabel('Amplitude');
Output:
a) Signal addition
b) Signal multiplication
c) Scaling
d) Shifting
e) Folding
Result:
Aim: To write a program to perform convolution of two given sequences (without using
built-in function) and display the signals.
Theory: Write relevant theory with the expression and an example for convolution.
Consider 𝑥(𝑛) = {1, 2, 3, 1} and ℎ(𝑛) = {1, 2 , 1, −1} and perform convolution.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc
% Take input for the signal x(n)
x_start = input('Enter the starting index of x(n): ');
x = input('Enter the input signal x(n): ');
len_x = length(x); % Length of the input signal x(n)
Output:
Enter the starting index of x(n): 0
Enter the input signal x(n): [1 2 3 1]
Enter the starting index of h(n): -1
Enter the impulse response h(n): [1 2 1 -1]
The convolution result y(n):
1 4 8 8 3 -2 -1
Result:
The program to perform convolution of two discrete-signal signals was written and
the output was verified successfully.
Experiment No. 4
System Function and Impulse Response of a Causal System
Aim: To write a program to determine the system function and impulse response of a
given causal system.
Problem Statement:
Consider a causal system 𝑦(𝑛) = 0.9𝑦(𝑛 − 1) + 𝑥(𝑛). Find system function and poles
and zeros and determine impulse response theoretically.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
% Coefficients of the system
x= [1 0]; % Coefficients of x(n), corresponding to numerator
y= [1 -0.9]; % Coefficients of y(n), corresponding to denominator
% H(z) = Y(z)/X(z)
H=tf(x, y, -1) % Transfer function (discrete-time)
% Pole-Zero Plot
figure;
zplane(x, y);
title('Pole-Zero Plot of the System');
grid on;
% Frequency response
w=linspace(-pi, pi, 1000); % Define frequency range
H_freq=freqz(x,y,w); % Compute frequency response
% Plot Magnitude response |H(e^jω)|
figure;
subplot(2,1,1);
plot(w,abs(H_freq));
title('Magnitude Response |H(e^{j\omega})|');
xlabel('Frequency (rad/sample)'); ylabel('Magnitude');
grid on;
% Plot Phase response ∠H(e^jω)
subplot(2,1,2);
plot(w,angle(H_freq));
title('Phase Response ∠H(e^{j\omega})');
xlabel('Frequency (rad/sample)'); ylabel('Phase (radians)');
grid on;
% Impulse response
n=-10:10; % Sample indices
h=impz(x,y,n) % Compute impulse response
% Plot impulse response
figure;
stem(n,h);
title('Impulse Response h(n)');
xlabel('n (samples)'); ylabel('h(n)');
grid on;
Output:
H =
z
-------
z - 0.9
h =
0
0
0
0
0
0
0
0
0
0
1.0000
0.9000
0.8100
0.7290
0.6561
0.5905
0.5314
0.4783
0.4305
0.3874
0.3487
a) Pole-Zero Plot
b) Frequency Response
c) Impulse Response
Result:
The program to determine the system function and impulse response of a given
causal system was written and the outputs were verified successfully.
Experiment No. 5
Computation of N-Point DFT
Aim: To write a program to compute N-point DFT of a given sequence (without using
built-in function) and plot the magnitude and phase spectrum.
Theory: Write relevant theory with the expression and an example for N-point DFT.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
% Input the sequence
x = input('Enter the sequence x[n]: ');
% Length of the sequence
N = length(x);
% Initialize DFT matrix
X = zeros(1, N);
% Compute N-point DFT
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1) + x(n+1) * exp(-1i * 2 * pi * k * n / N);
end
end
% Frequency index
k = 0:N-1;
Result:
The program to compute N-point DFT of a given sequence was written and the
magnitude and phase spectrum were plotted and the output was verified.
Experiment No. 6 (a)
Circular Convolution using DFT and IDFT
Aim: To write a program to compute circular convolution of two given sequences using
DFT and IDFT.
Theory: Write relevant theory for circular convolution using DFT and IDFT.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc
% Input two sequences
x1 = input('Enter the first sequence x1[n]: ');
x2 = input('Enter the second sequence x2[n]: ');
% Plot Signal x1
subplot(3,1,1);
stem(0:N-1, x1_pad);
title('Signal x1[n]');
xlabel('n'); ylabel('x1[n]'); grid on;
% Plot Signal x2
subplot(3,1,2);
stem(0:N-1, x2_pad);
title('Signal x2[n]');
xlabel('n'); ylabel('x2[n]'); grid on;
Output:
Enter the first sequence x1[n]: [2 1 2 1]
Enter the second sequence x2[n]: [1 2 3 4]
The Circular Convolution of the given sequences is:
14 16 14 16
Result:
The program to compute circular convolution of two given sequences using DFT
and IDFT was written and the output was verified.
Experiment No. 6 (b)
Linear Convolution using DFT and IDFT
Aim: To write a program to compute linear convolution of two given sequences using
DFT and IDFT.
Theory: Write relevant theory for linear convolution using DFT and IDFT.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc
% Input two sequences
x = input('Enter the sequence x(n): ');
h = input('Enter the sequence h(n): ');
% Plot Signal x1
subplot(3,1,1);
stem(0:N-1, x_pad);
title('Signal x[n]');
xlabel('n'); ylabel('x[n]'); grid on;
% Plot Signal x2
subplot(3,1,2);
stem(0:N-1, h_pad);
title('Signal h[n]');
xlabel('n'); ylabel('h[n]'); grid on;
Output:
Enter the sequence x(n): [1 2 3 1]
Enter the sequence h(n): [1 2 1 -1]
The Linear Convolution of the given sequences is:
1.0000 4.0000 8.0000 8.0000 3.0000 -2.0000 -1.0000
Enter the first sequence x1[n]: [2 1 2 1]
Result:
The program to compute linear convolution of two given sequences using DFT
and IDFT was written and the output was verified.
Experiment No. 7
Verification of DFT Properties
Aim: To write programs to verify linearity property, circular time shift property & circular
frequency shift property of DFT.
Theory: Write relevant theory for linearity property, circular time shift property & circular
frequency shift property of DFT.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Programs:
a) Linearity Property
clc;
subplot(2,1,1);
stem(0:N-1, abs(lhs));
title('Magnitude of LHS (DFT of a1*x1[n] + a2*x2[n])');
xlabel('Frequency Index'); ylabel('Magnitude'); grid on;
subplot(2,1,2);
stem(0:N-1, abs(rhs));
title('Magnitude of RHS (a1*DFT(x1[n]) + a2*DFT(x2[n]))');
xlabel('Frequency Index'); ylabel('Magnitude'); grid on;
k = 0:N-1;
% Compute the RHS of the property
rhs = X .* (exp(-1i * 2 * pi * k * m / N));
subplot(2, 1, 1);
stem(k, abs(lhs));
title('Magnitude of LHS: DFT of shifted x(n)');
xlabel('Frequency Index'); ylabel('Magnitude');
grid on;
subplot(2, 1, 2);
stem(k, abs(rhs));
title('Magnitude of RHS: Original DFT with phase shift');
xlabel('Frequency Index'); ylabel('Magnitude');
grid on;
c) Circular Frequency Shift Property
clc
subplot(2, 1, 1);
stem(0:N-1, abs(lhs));
title('Magnitude of LHS: DFT of frequency-shifted x(n)');
xlabel('Frequency Index'); ylabel('Magnitude');
grid on;
subplot(2, 1, 2);
stem(0:N-1, abs(rhs));
title('Magnitude of RHS: Circularly shifted DFT of x(n)');
xlabel('Frequency Index'); ylabel('Magnitude');
grid on;
Output:
a) Linearity Property
Enter the first sequence x1[n]: [1 2 3 4]
Enter the second sequence x2[n]: [4 5 2]
Enter the constant a1: 2
Enter the constant a2: 3
Left-hand side (DFT of a1*x1[n] + a2*x2[n]):
53.0000 + 0.0000i 2.0000 -11.0000i -1.0000 + 0.0000i 2.0000 +11.0000i
Result:
The programs to verify linearity property, circular time shift property & circular frequency
shift property of DFT were written and the output was verified.
Experiment No. 8
Decimation-in-Time Radix-2 FFT
Aim: To write a program to develop decimation-in-time radix-2 FFT algorithm without using
built-in functions
Theory: Write relevant theory for decimation-in-time radix-2 FFT algorithm including butterfly
diagram.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc;
x = input('Enter the input sequence x(n): '); % Input sequence
N = input('Enter the value of N: '); % FFT length (must be a power of 2)
subplot(2, 1, 2);
stem(0:N-1, angle(X)); % Phase plot
title('Phase of FFT');
xlabel('Frequency Index k');
ylabel('\angle X(k) (radians)');
grid on;
% Ensure N is a power of 2
if log2(N) ~= floor(log2(N))
error('N must be a power of 2');
end
len = len * 2; % Double the FFT length for the next stage
end
end
Output:
Enter the input sequence x(n): [1 2 3 4]
Enter the value of N: 8
FFT of the input:
Columns 1 through 7
Column 8
-0.4142 + 7.2426i
Result:
The program to develop decimation-in-time radix-2 FFT algorithm was written and the output
was verified.
Experiment No. 9
Digital Low Pass FIR Filter
Aim: To write a program for the design and implementation of a digital low pass FIR filter using a
window to meet the given specifications
Theory: Write relevant theory for digital low pass FIR filter and different windows.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc;
The program for the design and implementation of a digital low pass FIR filter using a window to
meet the given specifications is written and the output is verified.
Experiment No. 10
Digital High Pass FIR Filter
Aim: To write a program for the design and implementation of a digital high pass FIR filter using
a window to meet the given specifications
Theory: Write relevant theory for digital high pass FIR filter and different windows.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc;
The program for the design and implementation of a digital high pass FIR filter using a window to
meet the given specifications is written and the output is verified.
Experiment No. 11
Digital IIR Butterworth Low Pass Filter
Aim: To write a program for the design and implementation of a digital IIR Butterworth low pass
filter to meet the given specifications
Theory: Write relevant theory for digital IIR Butterworth low pass filter.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc;
% Normalized frequencies
wp = fp / (Fs / 2); % Passband edge frequency (normalized)
ws = fs / (Fs / 2); % Stopband edge frequency (normalized)
subplot(2, 1, 2);
plot(t, output_signal);
grid on;
title('Filtered Signal (Output)');
xlabel('Time (s)'); ylabel('Amplitude');
Output:
Enter the sampling frequency (Hz): 1000
Enter the passband frequency (Hz): 40
Enter the stopband frequency (Hz): 150
Enter the passband ripple (dB): 3
Enter the stopband ripple (dB): 60
Result:
The program for the design and implementation of a digital IIR Butterworth low pass filter to
meet the given specifications is written and the output is verified.
Experiment No. 12
Digital IIR Butterworth High Pass Filter
Aim: To write a program for the design and implementation of a digital IIR Butterworth high pass
filter to meet the given specifications
Theory: Write relevant theory for digital IIR Butterworth high pass filter.
Procedure:
• Open MATLAB.
• Click on New Script.
• In the editor, type the program.
• Save the file with .m extension.
• Run the file by pressing Run or typing the filename in the command window.
Program:
clc;
% Normalized frequencies
wp = fp / (Fs / 2); % Passband edge frequency (normalized)
ws = fs / (Fs / 2); % Stopband edge frequency (normalized)
subplot(2, 1, 2);
plot(t, output_signal);
grid on;
title('Filtered Signal (Output)');
xlabel('Time (s)'); ylabel('Amplitude');
Output:
Enter the sampling frequency (Hz): 1000
Enter the passband frequency (Hz): 40
Enter the stopband frequency (Hz): 150
Enter the passband ripple (dB): 3
Enter the stopband ripple (dB): 60
Result:
The program for the design and implementation of a digital IIR Butterworth high pass filter to
meet the given specifications is written and the output is verified.