0% found this document useful (0 votes)
13 views14 pages

DSP File - 1 To 3 - Merged

The document outlines a series of experiments conducted in a Digital Signal Processing lab using MATLAB, covering topics such as plotting basic signals, linear convolution, quantization, z-transform, and Discrete Fourier Transform (DFT). Each experiment includes aims, theoretical background, MATLAB code, and results demonstrating successful implementation of the concepts. The document serves as a comprehensive lab file for students to understand and apply key signal processing techniques.

Uploaded by

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

DSP File - 1 To 3 - Merged

The document outlines a series of experiments conducted in a Digital Signal Processing lab using MATLAB, covering topics such as plotting basic signals, linear convolution, quantization, z-transform, and Discrete Fourier Transform (DFT). Each experiment includes aims, theoretical background, MATLAB code, and results demonstrating successful implementation of the concepts. The document serves as a comprehensive lab file for students to understand and apply key signal processing techniques.

Uploaded by

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

DELHI TECHNOLOGICAL

UNIVERSITY

Digital Signal Processing


LAB FILE
EC 304
NAME : SAHIL SHAMIM
ROLL NO. : 2K22/EC/196
SEMESTER: 6
EXPERIMENT 1
Aim: To write a program to plot basic signals in continuous and discrete form using
MATLAB.

Software: MATLAB

Theory: If the amplitude of a signal is defined at every instant of time then it is called
continuous time signal. If the amplitude of the signal is defined only at some instants of
time, then the signal is called discrete time signal.

Unit Step Signal: Represented as u(t) in continuous time or u[n] in discrete time.

1. Continuous time: u(t) = 1 for t >= 0, and 0 otherwise.


2. Discrete time: u[n] = 1 for n >= 0, and 0 otherwise.

Unit Impulse Signal: Represented as delta(t) in the continuous domain, also known as
the Dirac-delta function.

It is defined by its properties in integrals. It exists only at t = 0, and its area equals
unity.

Unit Impulse Sequence: Represented as delta[n] in discrete time.

1. Defined as delta[n] = 1 for n = 0, and 0 otherwise.

Unit Ramp Signal: Represented as ur(t).

1. ur(t) = t for t >= 0, and 0 for t < 0.

Exponential Signal:

1. In the continuous domain:


Growing exponential: x(t) = a^t for all t.
Decaying exponential: x(t) = a^-t for all t.
2. In the discrete domain: x[n] = a^n.
If a > 1, it is a growing exponential. If a < 1, it is a decaying exponential.

Sine and Cosine Signals:

1. Continuous domain: x(t) = A sin(2 pi f t + theta).


2. Discrete domain: x[n] = A sin(omega n + theta).
Here, A is the amplitude, f is the frequency, and theta is the phase shift.

2
CODE:
figure('Name','Basic Signals Continuous');
x = linspace(-10,10,1000);
t = linspace(-10,10,10);
yc1 = (x >= 0);
yc2 = zeros(size(x));
[~, zero_idx] = min(abs(x));
yc2(zero_idx) = 1;
yc3 = x.*yc1;
yc4 = exp(x);
yc5 = exp(-x);
yc6 = sin(2*pi*x*100);
yc7 = cos(2*pi*x*100);
subplot(331);
plot(x,yc1);
grid on; xlabel('Time'); ylabel('Amplitude'); title('Unit Step');

subplot(332);
plot(x,yc2,'LineWidth', 2); grid on; xlabel('Time'); ylabel('Amplitude'); title('Unit Impulse');

subplot(333);
plot(x,yc3); grid on; xlabel('Time'); ylabel('Amplitude'); title('Ramp');

subplot(334);
plot(x,yc4); grid on; xlabel('Time'); ylabel('Amplitude'); title('Growing Exponential');

subplot(335);
plot(x,yc5); grid on; xlabel('Time'); ylabel('Amplitude'); title('Decaying Exponential');

subplot(336);
plot(x,yc6); grid on; xlabel('Time'); ylabel('Amplitude'); title('Sine');

subplot(337);
plot(x,yc7); grid on; xlabel('Time'); ylabel('Amplitude'); title('Cosine');

figure('Name','Basic Signals Discrete');


yd1 = (t >= 0);
yd2 = zeros(size(t));
[~, zero_idx] = min(abs(t));
yd2(zero_idx) = 1;
yd3 = t.*yd1;
yd4 = 2.^(t);
yd5 = (1/2).^(t);
yd6 = sin(2*pi*t*100);
yd7 = cos(2*pi*t*100);

subplot(331);
stem(t,yd1);
grid on; xlabel('Time'); ylabel('Amplitude'); title('Unit Step');

subplot(332);
stem(t,yd2); grid on; xlabel('Time'); ylabel('Amplitude'); title('Unit Impulse');

subplot(333);
stem(t,yd3); grid on; xlabel('Time'); ylabel('Amplitude'); title('Ramp');

3
subplot(334);
stem(t,yd4); grid on; xlabel('Time'); ylabel('Amplitude'); title('Growing Exponential');

subplot(335);
stem(t,yd5); grid on; xlabel('Time'); ylabel('Amplitude'); title('Decaying Exponential');

subplot(336);
stem(t,yd6); grid on; xlabel('Time'); ylabel('Amplitude'); title('Sine');

subplot(337);
stem(t,yd7); grid on; xlabel('Time'); ylabel('Amplitude'); title('Cosine');

Output:

Result: Successfully plotted basic signals, like unit impulse, unit step, ramp,
exponential, and sinusoidal signals, in both continuous and discrete forms using
MATLAB.

4
EXPERIMENT 2
Aim: To write a program to compute linear convolution of two discrete time signals.

Software: MATLAB

Theory: Linear convolution is a fundamental operation in signal processing used to


determine the output of a linear time-invariant (LTI) system for a given input signal and
system impulse response.

The linear convolution of an N-point vector, x, and an L-point vector, y, has length N+ L -
1.

Applications of Linear Convolution:

o Filtering: Used in digital filters to process signals.

o Image Processing: Applied for edge detection and blurring.

CODE:
figure('Name','Linear Convolution');

x1 = randi([-10 10],1,10);
x2 = randi([-10 10],1,10);

%x1 = [1 2 3 4];
%x2 = [2 1 -1 0];

a = length(x1) + length(x2) - 1;

y = zeros(1,a);
for i = 1:length(x1)
for j = 1:length(x2)
y(i + j - 1) = y(i + j - 1) + x1(i) * x2(j);
end
end
disp(x1);
disp(x2);

disp(y);

subplot(311);
stem(x1);grid on;title('x1');ylabel('Magnitude');

subplot(312);
stem(x2);grid on;title('x2');ylabel('Magnitude');

subplot(313);
stem(y);grid on;title('y = x1 * x2');ylabel('Magnitude');

5
Output:

Result: Successfully generated linear convolution of two discrete time signals using
MATLAB.

6
EXPERIMENT 3
Aim: To quantize a discrete time signal in MATLAB.

Software: MATLAB

Theory: Quantization is the process of converting a continuous signal into a discrete set
of values. This process is essential for analog-to-digital conversion (ADC). During
quantization, each discrete value of the signal x[n] is mapped to the nearest level from a
finite set of quantization levels.

The output of quantization consists of discrete representation levels. The difference


between two adjacent representation levels is called the step size or quantum.

CODE:

figure('Name','Quantization'); s =
randi([-20 20],1,10);

bits = 3;
levels = 2^bits;
n = 0:length(s)-1;
s_min = min(s);
s_max = max(s);
step_size = (s_max - s_min)/levels;

quantized_signal = round((s - s_min)/step_size) * step_size + s_min; subplot(211);


stem(n,s);title('Original Signal'); grid on; ylabel('Magnitude');

subplot(212);
stem(n,quantized_signal);title('Quantized Signal'); grid on; ylabel('Magnitude'); disp('Original Signal');
disp(s);
disp('Quantized Signal');
disp(quantized_signal);

Output:

7
Result: Successfully quantized the discrete time signal using MATLAB.

8
EXPERIMENT 4

Aim: To study the z-transform and plot the ROC for a discrete time signal using
MATLAB.
Software: MATLAB

Theory:

The z-transform is a powerful mathematical tool used for analyzing discrete-time


signals and systems. It provides a frequency domain representation of the
signals, making system analysis more efficient. The region of convergence (ROC)
defines the set of z-values for which the z-transform of a given signal converges,
indicating where the transformation is valid.

CODE:

n = 0:10;
x = 0.5.^n;
% Compute the z-transform syms
z;
X_z = sum(x .* z.^(-n)); % Z-transform formula for the given signal

% Display the z-transform


disp('The z-transform of the signal X(z) is:'); disp(X_z);

roc_limit = 0.5;
% Plot the ROC
theta = linspace(0, 2*pi, 1000); % Angular values for the unit circle z_unit_circle = exp(1j * theta); %
Points on the unit circle

figure;
hold on;
% Plot the unit circle
plot(real(z_unit_circle), imag(z_unit_circle), 'b--', 'LineWidth', 1);
% Plot the boundary of the ROC
r = roc_limit; % Radius for the ROC boundary
roc_boundary = r * exp(1j * theta); % Points on the ROC boundary plot(real(roc_boundary),
imag(roc_boundary), 'r', 'LineWidth', 1.5);

% Shade the ROC (outside the boundary)


fill(real(roc_boundary), imag(roc_boundary), 'r', 'FaceAlpha', 0.1, 'EdgeColor', 'none');

% Enhance the plot xlabel('Real


Part'); ylabel('Imaginary Part');
title('Region of Convergence (ROC) in the z-Plane');
legend({'Unit Circle', 'ROC Boundary', 'ROC'}, 'Location', 'best'); grid on;

9
Output:

The z-transform of the signal X(z) is:

1/(2*z) + 1/(4*z^2) + 1/(8*z^3) + 1/(16*z^4) + 1/(32*z^5) + 1/(64*z^6) +


1/(128*z^7) + 1/(256*z^8) + 1/(512*z^9) + 1/(1024*z^10) + 1

Result: The z-transform of the discrete time signal was studied, and the ROC
was plotted successfully using MATLAB.

1
0
EXPERIMENT 5

Aim:To study the Discrete Fourier Transform (DFT) and its linearity and convolution
property using MATLAB.
Software: MATLAB

Theory:

The Discrete Fourier Transform (DFT) is a mathematical tool used to decompose


discrete-time signals into their constituent frequency components. The linearity
property of the DFT states that the transform of a sum of signals is equal to the sum
of their individual transforms. Similarly, the convolution property establishes a
relationship between the DFT of a convolution operation and the product of the
DFTs of the individual signals.

CODE:

% Define new discrete-time signals


x1 = [1, -1, 2, 0, 3]; % First signal
x2 = [2, 3, 1, -1, 0]; % Second signal

% Define scalar multipliers for linearity property


a = 3; % Scalar for x1
b = -2; % Scalar for x2

% LINEARITY PROPERTY
% Compute the DFT of individual signals
X1 = fft(x1);
X2 = fft(x2);

% Compute the combined signal and its DFT


x_combined = a * x1 + b * x2; % Combined signal
X_combined = fft(x_combined); % DFT of the combined signal

% Verify linearity by combining individual DFTs


X_linear = a * X1 + b * X2;

% Display results
disp('Verifying Linearity Property:');
disp('DFT of combined signal:');
disp(X_combined);
disp('Combined DFT of individual signals:');
disp(X_linear);

% Check if the results match


if isequal(round(X_combined, 10), round(X_linear, 10))
disp('Linearity property verified!');
else
disp('Linearity property not satisfied!'); 1
end 1
% Compute the circular convolution using DFT
Y_circular_conv = ifft(fft(x1) .* fft(x2)); % Circular convolution in frequency domain

% Compute the linear convolution using the conv function


y_linear_conv = conv(x1, x2);

% Pad signals to the same length for circular convolution


N = max(length(x1), length(x2));
x1_padded = [x1, zeros(1, N - length(x1))];
x2_padded = [x2, zeros(1, N - length(x2))];
Y_padded_circular_conv = ifft(fft(x1_padded) .* fft(x2_padded));

% Display convolution results


disp('Verifying Convolution Property:');
disp('Circular Convolution Result (Frequency Domain):');
disp(Y_circular_conv);
disp('Linear Convolution Result (Time Domain):');
disp(y_linear_conv);
disp('Circular Convolution with Padding:');
disp(Y_padded_circular_conv);

% Plot the results


figure;

% Plot original signals


subplot(3, 1, 1);
stem(0:length(x1)-1, x1, 'filled'); hold on;
stem(0:length(x2)-1, x2, 'filled');
title('Original Signals x1 and x2');
xlabel('n');
ylabel('Amplitude');
legend('x1', 'x2');
grid on;

% Plot DFT results


subplot(3, 1, 2);
stem(0:length(X1)-1, abs(X1), 'filled'); hold on;
stem(0:length(X2)-1, abs(X2), 'filled');
title('DFT of Signals |X1(k)| and |X2(k)|');
xlabel('k');
ylabel('Magnitude');
legend('|X1(k)|', '|X2(k)|');
grid on;

% Plot convolution results


subplot(3, 1, 3);
stem(0:length(y_linear_conv)-1, y_linear_conv, 'filled', 'DisplayName', 'Linear Convolution');
hold on;
stem(0:length(Y_padded_circular_conv)-1, real(Y_padded_circular_conv), 'filled', 'DisplayName',
'Circular Convolution');
title('Convolution Results');
xlabel('n');
ylabel('Amplitude');
legend;
grid on;
1
2
sgtitle('Study of DFT, Linearity, and Convolution Property');

Output:

Result: The DFT and its linearity and convolution property were successfully studied
and implemented using MATLAB.

1
3
1
4

You might also like