DSP Lab Report11708039
DSP Lab Report11708039
Lab-Report
On on
Different Types of Digital Signal
Course Title: Digital Signal Processing Lab
Submitted To:
Name: Khairun Nahar
Assistant Professor
Department of CSE Submitted By:
Comilla University Name: Md. Kaysar Ahmed
Id: 11708039
Session: 2016-2017
Department of CSE
Comilla University
Date: 16-01-2022
Problem No: 01
Problem Statement: Sampling an analog signal using MATLAB.
Theory:
Sampling is the first step to convert continuous-time signal into discrete time signal obtained
by taking “samples” of the continuous-time signal at discrete-time instants.
Procedure: The functions used in MATLAB to implement this program are given below:
Syntax : subplot(m,n,p)
subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes in the position
specified by p. MATLAB numbers subplot positions by row. The first subplot is the first
column of the first row, the second subplot is the second column of the first row, and so on. If
axes exist in the specified position, then this command makes the axes the current axes.
Syntax : Y = sin(X)
Y = sin(X) returns the sine of the elements of X. The sin function operates element-wise on
arrays. The function accepts both real and complex inputs.
For real values of x, sin(x) returns real values in the interval [-1, 1].
For complex values of x, sin(x) returns complex values.
Syntax : stem(X,Y)
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be
vectors or matrices of the same size. Additionally, X can be a row or column vector and Y
must be a matrix with length(X) rows.
If X and Y are both matrices, then stem plots columns of Y against corresponding columns of
X.
Sample Input Output:
Conclusion: To convert a signal from continuous time to discrete time, a process called
sampling is used. The value of the signal is measured at certain intervals in time. Each
measurement is referred to as a sample. The sampling output for the given input signal is
using MATLAB is correctly produced.
Problem No:02
Problem Statement: Quantization of an analog signal using MATLAB.
Theory:
Quantization is the conversion of a discrete-time continuous-valued signal into a discrete-
time, discrete-valued signal. The value of each signal sample is represented by a value
selected from a finite set of possible values The difference between the unquantized sample
x(n) and the quantized output 𝑥𝑞(n) is called the quantization error.
The result of sampling is a series of pulses with amplitude values between the maximum and
minimum amplitudes of the signal. The set of amplitude can be infinite with nonintegral
values between the two limits. These values cannot be used in the encoding process. The
following are the steps in quantization:
1. We assume that the original analog signal has instantaneous amplitude between Vmin
and Vmax.
2. We divide the range into L zones, each of height ∆ (delta).
∆ = Vmax – Vmin / L
3. We assign quantized values of 0 to L-1 to the midpoint of each zone.
4. We approximate the value of the sample amplitude to the quantized values.
Procedure: The Functions used in MATLAB to implement this program are given below:
Syntax: Y = sin(X)
Y = sin(x) returns the sine of the elements of x. The sin function operates element-wise on
arrays. The function accepts both real and complex inputs.
For real values of x, sin(x) returns real values in the interval [-1, 1].
For complex values of x, sin(x) returns complex values.
Syntax: Y = sin(x)
Y = cos(x) returns the cosine for each element of x. The cos function operates
element-wise on arrays. The function accepts both real and complex inputs.
For real values of x, cos(x) returns real values in the interval [-1, 1].
plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding values in X.
If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y
versus columns of X.
Conclusion: The quantization output for the given signal using MATLAB is produced easily
without any error.
Problem No: 03
Problem Statement: Generate continuous and discrete time signal using MATLAB.
Theory:
Continuous-time signal: Continuous-time signal is the “function of continuous-time variable that
has uncountable or infinite set of numbers in its sequence”. The continuous-time signal can be
represented and defined at any instant of the time in its sequence. The continuous- time signal is
also termed as analog signal.
Discrete-time signal: Discrete-time signal is the “function of discrete-time variable that has
countable or finite set of numbers in its sequence”. It is a digital representation of continuous- time
signal. The discrete-time signal can be represented and defined at certain instants of time in its
sequence.
Procedure: The functions used in MATLAB to implement this program are given below:
subplot(m,n,p)
Syntax: plot(X,Y)
plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding values in X.
If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y
versus columns of X.
Syntax: grid
grid toggles the visibility of the major grid lines.
Conclusion: The sample output for the given input signal using MATLAB is correctly produced.
Problem No:04
Problem Statement: Generate even signal using MATLAB.
Theory: A real valued signal x(n) is called even if x(-n) = x(n). A signal is referred to as an even
if it is identical to its time reversed counters parts. Even signal is symmetric around vertical axis.
The even signal component is formed by adding x(n) to x(-n) and dividing by 2 that is,
Xe(n) = ½[x(n) + x(-n)]
Procedure: The functions used in MATLAB to implement this program are given below:
Syntax: B = flipper(A)
B = flipper(A) returns A with its columns flipped in the left-right direction (that is, about a vertical
axis).
Syntax: axis(limits)
axis(limits) specifies the limits for the current axes. Specify the limits as vector of four, six, or eight
elements.
Syntax: stem (X, Y)
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be vectors
or matrices of the same size. Additionally, X can be a row or column vector and Y must be a matrix
with length(X) rows.
If X and Y are both matrices, then stem plots columns of Y against corresponding columns of X.
Syntax: grid
grid toggles the visibility of the major grid lines.
Conclusion: The sample output for the given input signal using MATLAB is correctly produced.
Problem No:05
Problem Statement: Generating an odd signal using MATLAB.
Theory: A signal x(n) is called antisymmetric(odd) if
x(-n) = x(n)
Odd signals are important in many areas of mathematical analysis. An odd signal must be zero at
n=0. In other words, odd signal passes the origin.
The odd signal component is formed by subtracting x(-n) from x(n) and dividing by 2.
X0(n) = ½ [x(n) – x(-n)]
Problem No:06
Problem Statement: Generating a deterministic continuous signal using MATLAB.
Theory: Any continuous signal that can be uniquely described by an mathematical expression, a
table of data or well defined rule is called deterministic continuous signal. For this signal, it is
possible to predict the amplitude at a given instant of time. A good example of deterministic
continuous signal is a signal composed of a single sinusoid such as
x(t) = A cos (2π𝑓0t+ϕ)
with the signal parameters being:
(A, 𝑓0, ϕ)
A= Amplitude, 𝑓0= Frequency in hertz Φ= Phase in radians
x(t) is deterministic because the signal parameters are constants.
Procedure: The functions used in MATLAB to implement this program are given below:
Syntax: Y = sin(X)
Y = sin(x) returns the sine of the elements of x. The sin function operates element-wise on arrays.
The function accepts both real and complex inputs.
For real values of x, sin(x) returns real values in the interval [-1,1].
For complex values of x, sin(x) returns complex values.
Syntax: Y=exp(X)
Y=exp(X) returns the exponential ex for each element in array X. For complex elements z =
x +iy, it returns the complex exponential.
ez =ex(cosy+isiny)
Problem No:07
Problem Statement: Generate damped signal using MATLAB.
Theory: A damped signal is a signal whose amplitude of oscillation decreases with time,
eventually going to zero, an exponentially decaying sinusoidal signal.
An ideal damped signal is an exponentially decreasing sinusoid; an oscillating sine (or cosine) wave
in which the peak amplitude decreases from an initial maximum toward zero at an exponentially.
We can write a general equation for an exponentially damped sinusoid as –
y(t) = A.𝑒−𝜆𝑡 (cos(ωt+φ) +(sin(ωt+φ)))
y(t) = A.𝑒−𝜆𝑡 (cos(ωt+φ))
where
A is the initial amplitude (the highest peak)
λ is the decay constant
φ is the phase angle (at t =0)
ω is the angular frequency
Procedure: The functions used in MATLAB to implement this program are given below:
Syntax : plot(X,Y)
plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding values in X.
If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y
versus columns of X.
Syntax: Y = cos(X)
Y = cos(X) returns the cosine for each element of X. The cos function operates element-wise on
arrays. The function accepts both real and complex inputs.
For real values of x, cos(x) returns real values in the interval [-1,1]
Syntax: Y = exp(X)
Y = exp(X) returns the exponential ex for each element in array X. For complex elements z = x + iy,
it returns the complex exponential
ez=ex(cosy+isiny) .
Conclusion: The sample output for the given input signal using MATLAB is correctly produced.
Problem No:08
Problem Statement: Generate unit ramp/sample/exponential signal.
Theory:
Discrete time signals and systems has a number of basic signals that appear often and play
important role. These signals are unit sample sequence, unit ramp signal and exponential signals.
1, 𝑓𝑜𝑟 𝑛 = 0
δ (n)= {
0, 𝑓𝑜𝑟 𝑛 ≠ 0
The unit sample sequence is a signal that is zero everywhere, except at n=0 where its value is unity.
The signal is sometime referred as a unit impulse.
Unit Ramp Signal:
The unit ramp signal is denoted as 𝑢𝑟(n) and is defined as
Exponential Signal:
The exponential signal is a sequence of the form
X(n) = 𝑎𝑛 for all n
If the parameter a is real, then x(n) is real signal.
𝑎 = 𝑟𝑒𝑗𝜃
Where r and are now the parameters. Here x(n) as
𝑥(𝑛) = 𝑟𝑛𝑒𝑗𝜃𝑛
= 𝑟𝑛(cos 𝜃𝑛 + 𝑗 sin 𝜃𝑛)
Since x(n) is now complex valued, it can be represented graphically by plotting the real part,
𝑥𝑅(𝑛) = 𝑟𝑛 cos
𝜃𝑛
𝑥1(𝑛) = 𝑟𝑛 sin
𝜃𝑛
Procedure: The functions used in MATLAB to implement this program are given below:
Syntax: stem (X, Y)
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be vectors
or matrices of the same size. Additionally, X can be a row or column vector and Y must be a matrix
with length(X) rows.
If X and Y are both matrices, then stem plots columns of Y against corresponding columns of X.
Syntax: xlabel(txt)
xlabel(txt) labels the x-axis of the current axes or chart returned by the gca command. Reissuing the
xlabel command replaces the old label with the new label.
Syntax: ylabel(txt)
ylabel(txt) labels the y-axis of the current axes or chart returned by the gca command. Reissuing the
ylabel command causes the new label to replace the old label.
syntax: title(txt)
title(txt) adds the specified title to the axes or chart returned by the gca command. Reissuing the
title command causes the new title to replace the old title.
Syntax: plot (X, Y)
plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding values in X.
If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y
versus columns of X.
Sample Input and Output:
Conclusion: The output of the signals(unit sample sequence, unit step signal, unit ramp signal,
exponential signal) using MATLAB is produced successfully.
Problem No:09
Problem Statement: Generate triangular/rectangular signal using MATLAB.
Theory: The triangle function is the function
The left figure above plots the function as defined, while the right figure shows how it would
appear if traced on an oscilloscope. The generalized function has height,center
and full-width.
Procedure:
Syntax: plot (X, Y)
plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding values in X.
If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y
versus columns of X.
Syntax: xlabel(txt)
xlabel(txt) labels the x-axis of the current axes or chart returned by the gca command. Reissuing the
xlabel command replaces the old label with the new label.
Syntax: ylabel(txt)
ylabel(txt) labels the y-axis of the current axes or chart returned by the gca command. Reissuing the
ylabel command causes the new label to replace the old label.
syntax: title(txt)
title(txt) adds the specified title to the axes or chart returned by the gca command. Reissuing the
title command causes the new title to replace the old title.
Conclusion: The value of the signal is measured at certain intervals in time. Each measurement is
referred to as a sample. The sampling output for the given input signal is using MATLAB is
correctly produced.
Problem No:10
Problem Statement: Perform convolution sum of discrete time signal with function (conv) and
without function using MATLAB.
Theory: Convolution is a mathematical way of combining two signals to form a third signal. It is
the single most important technique in Digital Signal Processing. Using the strategy of impulse
decomposition, systems are described by a signal called the impulse response. Convolution is
important because it relate the three signals of interests: the input signal, the output signal and the
impulse response.
Procedure:
Syntax: x= input(prompt)
x = input(prompt) displays the text in prompt and waits for the user to input a value and press the
Return key. The user can enter expressions, like pi/4 or rand (3), and can use variables in the
workspace.
Syntax: B = zeros(m,n)
B = zeros(m,n) or B = zeros([m n]) returns an m-by-n matrix of zeros.
Syntax: xlabel(txt)
xlabel(txt) labels the x-axis of the current axes or chart returned by the gca command. Reissuing the
xlabel command replaces the old label with the new label.
Syntax: ylabel(txt)
ylabel(txt) labels the y-axis of the current axes or chart returned by the gca command. Reissuing the
ylabel command causes the new label to replace the old label.
Syntax: stem(X,Y)
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be vectors
or matrices of the same size. Additionally, X can be a row or column vector and Y must be a matrix
with length(X) rows.
If X and Y are both matrices, then stem plots columns of Y against corresponding columns of X.
Syntax: title(txt)
title(txt) adds the specified title to the axes or chart returned by the gca command. Reissuing the
title command causes the new title to replace the old title.
Conclusion: The sample output for convolution sum of discrete-time signal using MATLAB is
produced correctly.
Problem No:11
Problem Statement: Perform cross-correlation using function.
Theory:
In signal processing, cross-correlation is a measure of similarity of two series as a function
of the displacement of one relative to the other. This is also known as a sliding dot product. It is
commonly used for searching a long signal for a shorter, known feature.
Properties of cross-correlation function of energy and power signals:
Auto correlation exhibits conjugate symmetry.
Cross correlation is not commutative like convolution.
Cross correlation function corresponds to the multiplication of spectrums of one
signal to the complex conjugate of spectrum of another signal
Procedure:
Syntax: subplot(m,n,p)
subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes in the position
specified by p. MATLAB numbers subplot positions by row. The first subplot is the first column of
the first row, the second subplot is the second column of the first row, and so on. If axes exist in the
specified position, then this command makes the axes the current axes.
Syntax: stem(X,Y)
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be vectors
or matrices of the same size. Additionally, X can be a row or column vector and Y must be a matrix
with length(X) rows.
If X and Y are both matrices, then stem plots columns of Y against corresponding columns of X.
Syntax: x= input(prompt)
str = input(prompt,'s')
x = input(prompt) displays the text in prompt and waits for the user to input a value and press the
Return key. The user can enter expressions, like pi/4 or rand(3), and can use variables in the
workspace.
Syntax: r = xcorr(x)
xcorr(x) returns the autocorrelation sequence of x. If x is a matrix, then r is a matrix whose columns
contain the autocorrelation and cross-correlation sequences for all combinations of the columns of
x.
Sample Input and Output:
Conclusion: The sample output for cross-correlation using MATLAB is produced successfully.
Problem No:12
Problem Statement: Perform z transformation using MATLAB.
Theory: Z transform is a domain in which there is conversion of discrete time signals that are
real or even complex numbers sequence into complex frequency domain representation.
The z-transform of a discrete time signal x(n) is defined as the power series-
𝑋(𝑧) ≡ ∑∞ 𝑥(𝑛)𝑧−𝑛
𝑛=−∞
Procedure:
Syntax: Ztrans(f)
Ztrans(f) finds the Z-Transform of f. by default, the independent variable is n and the
transformation variable is z. If f does not contain n, ztrans uses symvar.
Syntax: disp(X)
disp(X) displays the value of variable X without printing the variable name. Another way to
display a variable is to type its name, which displays a leading “X =” before the value.
If a variable contains an empty array, disp returns without displaying anything.
Syntax: pretty(X)
pretty(X) prints X in a plain-text format that resembles typeset mathematics. For true typeset
rendering, use Live Scripts instead.
Conclusion: The z-transform proves a useful, more general form of the Discrete Time Fourier
Transform. It applies equally well to describing systems as well as signals using the Eigen
function method, and proves extremely useful in digital filter design. The sample output for z-
transform the given input signal using MATLAB is correctly produced.
Problem No:13
Problem Statement: To Perform Inverse z Transformation.
Theory:
The procedure for transforming from the z-domain t the time domain is called the inverse z-
transform. An inversion formula for obtaining x(n) from X(z) can be derived by the Cauchy
integral theorem, which is an important theorem in the theory of complex variables.
To begin, we have the z-transform defined by (1) as,
Procedure: The functions used in doing this program are given bellow:
Syntax: iztrans(F)
iztrans(F) returns the Inverse Z-Transform of F. By default, the independent variable is z and the
transformation variable is n. If F does not contain z, iztrans uses the function symvar.
Syntax: disp(X)
disp(X) displays the value of variable X without printing the variable name. Another way to
display a variable is to type its name, which displays a leading “X =” before the value.
If a variable contains an empty array, disp returns without displaying anything.
Conclusion: The sample output for the inverse z-transform using MATLAB correctly
produced.
Problem No:14
Problem Statement: To perform folding on a discrete-time signal.
Theory: It is folding of signal about time origin n=0. In this case replace n by – n.
Conclusion: The sample output for folding of a discrete-time signal using MATLAB
produced.
Problem No:15
Problem Statement: To perform time shifting on a discrete-time signal.
Theory: Signal x(n) can be shifted in time. We can delay the sequence or advance the sequence.
This is done by replacing integer n by n-k where k is integer. If k is positive signal is delayed in
time by k samples (Arrow get shifted on left hand side) And if k is negative signal is advanced in
Conclusion: Output for time shifting of a discrete-time signal using MatLab is produced.