You are on page 1of 17

United International University

Department of Electrical and Electronics


Engineering
Digital signal processing Laboratory
Summer 212-EEE - 3310 – A
Tanzidul Aziz
ID: 021191049
Lab report – 01

Lab session name: Implementation of Discrete-Time Signals using


MATLAB.
Objective:
1. Describe discrete-time signals mathematically and generate,
manipulate, and plot discrete-time signals using MATLAB
2. To understand different operations on DT signals.
Construction:
Generation of DT signals using MATLAB.

Example1.1: Generate the sequence

Solution: The signal x(n) is a continuous signal, to plot this continuous signal in
the DT signal we use MATLAB built-in stem function. The stem function
converts continuous signal to DT signal.

Example1.2: Generate a sequence x(n) = [2,1, -1,3,1,4,3,7] represented


in MATLAB.
Solution: To generate a DT sequence we need a boundary state, here the arrow
sign means the zero position of the sequence. The left side of the arrow number
means the lower boundary position and the right side of the arrow number
means the position of the upper boundary.
Custom function for generation of DT signals:
This section needs some custom functions to perform an elementary function
like delta, unit step, exponential, etc. We need to build a custom function
because MATLAB has no elementary built-in function.
Name Mathematical MATLAB function
definition
1 Unit sample function
. δ(n)=¿ {1, n=0¿¿¿¿ function [x n] = delta (n0, n1,
n2)
n= [n1: n2];
x=[n-n0] = =0;
2 Unit step function
. u(n)=¿ {1 , n≥0¿¿¿¿ function [x n] = u (n0, n1, n2)
n= [n1: n2];
x=[n-n0]>=0;

3 Real valued x(n) = an,n; aR function [x n] = realx (a, n1, n2)
. exponential
n= [n1: n2];
sequence
x=a.^n;

Example1.3: Generate and plot the following sequences over the


indicated intervals.
(a) x (n) = 2(n+2) - (n-4); -5 ≤ n≤ 5.
(b) x(n) = cos(0.04n) +0.2w(n), 0 ≤ n ≤ 50, where w(n) is the
Gaussian random sequence with zero mean and unit variance.

Solution: Here question (a) is a delta signal, to plot this delta signal in
MATLAB we use a custom delta function. Question (b) continuous signal, also
there is part w(n) which is Gaussian random sequence, to plot this we use
“randn” MATLAB built-in function.

Example 1.4: Generate and plot the samples (use the stem function) of
the following sequence using MATLAB:
10
x 1 ( n )= ∑ (m+1) [ δ ( n−2 m ) −δ ( n−2 m−1 ) ]
(a) m=0 ; 0≤n≤25

(b) , one periodic, plot 10 periods


Solution: This section question (a) signal is a summation of a delta function
with a range of 0≤n≤25 also there is a range of m (0 to 10), to calculate this
signal we use a for loop to mention the range of m.
Question (b) is a real valued exponential sequence, so if we want to plot this
function in MATLAB, we need a custom function to generate the sequence. To
generate this sequence of 10 periods we use the MATLAB built-in function
“repmat”, which repeats the periods in 10 periods.

Operation on DT Sequences:
Custome function for Operation on DT Sequences:
This section also we need some custom function to perform some mathematical
operation like addition, multiplication, shifting, folding, decomposition, etc. We
need to build a custom function because MATLAB has no elementary built-in
function.

Name Mathematical MATLAB function


definition
1 Signal {x1(n)} +{x2(n)} function [y n] =sigadd (x1, n1, x2, n2)
. addition = {x1(n)+x2(n)}
n=min(min(n1), min(n2)):max(max(n1),
max(n2));
y1=zeros (1, length(n)); y2=y1;
y1(find((n>=min(n1)) &(n<=max(n1)) ==1)) =x1;
y2(find((n>=min(n2)) &(n<=max(n2)) ==1)) =x2;
y=y1+y2;
end
2 Signal {x1(n)}. {x2(n)} = function [y n] =sigmult (x1, n1, x2, n2)
. multiplic {x1(n).x2(n)}
n=min(min(n1), min(n2)):max(max(n1),
ation
max(n2));
y1=zeros (1, length(n)); y2=y1;
y1(find((n>=min(n1)) &(n<=max(n1)) ==1)) =x1;
y2(find((n>=min(n2)) &(n<=max(n2)) ==1)) =x2;
y=y.*y2;
end

3 Signal y(n)={x(n-k)} function [y n] =sigshift (x, m, n0)


. Shifting
n=m+n0;
y=x;
end

4 Signal y(n)={x(-n)} function [y n] = sigfold(x,n)


. folding
y=fliplr(x); n=-fliplr(n);
% fliplr is library function.
End
>> help fliplr in command window to know in
details.
5 Decompo function [xe, xo, m] = evenodd(x,n)
sition to m = -fliplr(n);
even and
odd part m1 = min([m,n]); m2 = max([m,n]); m = m1:m2;
nm = n (1)-m (1); n1 = 1: length (n);
x1 = zeros (1, length(m)); x1(n1+nm) = x; x = x1;
xe = 0.5*(x + fliplr(x)); xo = 0.5*(x – fliplr(x));
end

Example 1.5: Let x(n) = {1,2,3,4,5,6,7,6,5,4,3,2,1} Generate and plot


the following sequence using MATLAB:
(a) x1(n)=2x(n-5)-3x(n+4). (b) x2(n)=x(3-n) +x(n)x(n-2).
Solution: This section has various types of signal systems like signal adding,
folding, multiplication, shifting, even odd functions, etc. If we want to
generate this type of signal, we need a MATLAB custom function. For this
reason, we build some MATLAB custom functions.
Here question (a) signal has shifting, multiplication, adding function. (n-5)
means signal shift right by 5 and (n+4) means signal shift left by -4 from the
original sequence. Question (b) has a folding section also a multiplication and
a shifting section. To generate these two signals, we use the custom function.
Example 1.6: Real and Imaginary part of complex sequence
(−0. 1+ j 0. 3) n
Generate the complex-valued signal, x(n)=e , -10≤ n ≤ 10
and plot its magnitude, phase, the real part, and the imaginary part in four
separate subplots.
Solution: Complex signal has mainly two-part, one is the real part and another is
the imaginary part. The imaginary part has two sections, magnitude, and angle.
To plot this complex signal in separate parts we use MATLAB built-in function,
real(x), ‘imag(x)’, abs(x).

Example 1.7: Decomposing a sequence in even and odd components:

Use the function ‘evenodd(x,n )’ to decompose x(n) = into even and


odd components . Show original sequence, even part, and odd part in subplots.
Solution: Every function may be uniquely decomposed as the sum of
an even and an odd function, which is called respectively the even part and
the odd part of the function. Here x(n) is a continuous signal so we need to
decompose it to find the even and odd part of this signal.
Example 1.8: Use downsample (x,k) function to plot the original and
downsampled sequence in subplots, where, x(n) = {1 2 3 4 5 6 7 8 9 10 11 12}
and the downsampling factor is 3.
Solution: In signal processing, downsampling is the process of reducing the
sampling rate of a signal. This is usually done to reduce the data rate or the size
of the data.  Downsample reduces the sampling rate of the input signal by an
integer factor by picking up one out of K samples.
Example 1.9: Use upsample(x,k) function to plot the original and
downsampled sequence in subplots, where, x(n) = {2 3 4 5 6} and the
upsampling factor is 3.
Solution: Upsampling is the process of inserting zero-valued samples between
original samples to increase the sampling rate. In some cases, upsampling will
improve the output of our D/A converter. The low-pass filters incorporated into
the upsampling process will essentially replace the filters in our D/A converter.

Lab Evaluation:
ILE1.1: Using the evenodd function, decompose the following
sequences into their even and odd components. Plot these
components using the stem function.

Solution: In mathematics, even functions and odd functions are functions that
satisfy particular symmetry relations, concerning taking additive inverses. They
are important in many areas of mathematical analysis, especially the theory of
power series and Fourier series.
ILE1.2: Let . Generate and plot the samples

of the following sequence:


Solution: This sequence has multiplication, shifting, and signal addition
functions. So, we use the Operation on DT Sequences function to plot this
sequence.
ILE1.3: Let is one period of a periodic sequence. Plot
4 periods of the sequence.
Solution: This is the sequence of repetition periods of a DT signal.
Here x(n) is one periodic signal, if we want to plot this periodic
signal for 4 periods we use “repmat” MATLAB built-in function.

Home Work:
1. Generate and plot the samples (use the stem function) of the following
sequence using MATLAB: where
x (n)={1 ,−2,6 ,−5,4,6,8 ,10 } Hint: Use “sigadd” & “sigshift” functions.

Solution: This signal is under Operation on DT Sequences, here the x1(n) signal
has a shifting and addition function and the x(n) signal set the position of
shifting the position of the sequence, also this arrow sign means the position of
zero states.
2. (a) A unit ramp DT signal r(n) is defined as,

r(n)=¿ {n n≥0¿¿¿¿
Develop a function to implement the above signal.

(b) Use the above sequence to plot a ramp sequence for the interval -10 to 10.
Solution: ramp( x ) creates a ramp signal wave with a slope of 1 and returns the
value of the ramp at time x. To generate the ramp signal we use a custom-built
ramp function.

3) Generate x(n)= cos(0.25n), −50≤n≤50 . Downsample x(n) by a factor of 5


to generate y(n). Plot both x(n) and y(n) using subplot.
Solution: In digital signal processing, downsampling, compression, and
decimation are terms associated with the process of resampling in a multi-rate
digital signal processing system.
4) Let, x(n)={1,−2,6 ,−5,4,6,8 ,10 } Generate and plot the samples of the
following sequence. Hint: Use a for loop and “sigadd” & “sigshift”

functions.
Solution: This signal need Operation on DT Sequences and a for loop to
generate the signal. Here for loop is used to calculate the equation of the signal
under the condition.

5. A simple digital differentiator is given by y(n) = x(n) – x (n − 1) which


computes a backward first-order difference of the input sequence. Implement
this differentiator on the following sequences, and plot the results. Comment on
the appropriateness of this simple differentiator

(i)

(ii)
Solution: Here y(n) signal has two shifting positions. The first shifting is 0 and
the second shifting is the right shift by 1, to complete the state we use the
Custom function for the generation of DT signals of the unit step function.
i)

ii)
Summary: To process the analog signal by digital, we need to convert them into
digital signals. This process is called Analog-to-Digital conversion. In this lab
session, we use some analog continuous signals to convert DT signals. Some of
them need a custom function to perform, some use MATLAB built-in functions.
This lab session includes some separate parts like, mathematically part and
generates, manipulate, and plot discrete-time signals using, generation of DT
signals and some for Operation on DT Sequences.

You might also like