DSP File - 1 To 3 - Merged
DSP File - 1 To 3 - Merged
UNIVERSITY
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.
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.
Exponential Signal:
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');
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
The linear convolution of an N-point vector, x, and an L-point vector, y, has length N+ L -
1.
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.
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;
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:
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
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);
9
Output:
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:
CODE:
% LINEARITY PROPERTY
% Compute the DFT of individual signals
X1 = fft(x1);
X2 = fft(x2);
% Display results
disp('Verifying Linearity Property:');
disp('DFT of combined signal:');
disp(X_combined);
disp('Combined DFT of individual signals:');
disp(X_linear);
Output:
Result: The DFT and its linearity and convolution property were successfully studied
and implemented using MATLAB.
1
3
1
4