You are on page 1of 12

University of Technology

Department of Communication Engineering


Optical Communication Systems Engineering Branch

Generation Discrete time signal

Experiment No.1-Part(I)
Digital Signal Processing Laboratory I

Mousa Saad Luaibi Fourth year

Morning Study Group B


q

Wednesday, October 12, 2022

Tuesday, October 18, 2022

Iraq, Baghdad

coe.19.003@student.uotechnology.edu.iq
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

➢ Aim
To generate basic signals like unit impulse, unit step, unit ramp, exponential and sinusoidal
signals using MATLAB.

➢ Theory
Whether analog or digital, information is represented by the fundamental quantity in
electrical engineering the signal. Stated in mathematical terms, a signal is merely a function.
Analog signals are continuous-valued, digital signals are discrete-valued. The independent
variable of the signal could be time (speech, for example) space (images).

• Continuous-Time Signal: data are available or measured every time (or space) instant the
data are defined over a continuous input.
• Discrete-Time Signal: defined only for discrete points in time such as every minute, hour,
3 months, year, etc. You sample or collect data at these times only.

• Basic signals:
1. Unit samples sequence.
1, 𝑛 = 𝑛𝑜
𝛿[𝑛 − 𝑛𝑜 ] = {
0, 𝑛 ≠ 𝑛𝑜

2. Unit step sequence.


1, 𝑛 ≥ 𝑛𝑜
𝑢[𝑛 − 𝑛𝑜 ] = {
0, 𝑛 < 𝑛𝑜

3. Exponential Sequence.
𝑥[𝑛] = 𝑎𝑛 , ∀𝑛; 𝑎 ∈ 𝑅

4. Unit ramp sequence.


𝑛 × 𝑢(𝑛), 𝑛≥0
𝑢𝑟 [𝑛] = {
0, 𝑒𝑙𝑠𝑒

5. Sinusoidal sequence.
𝑥[𝑛] = sin(𝜔𝑛)
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

➢ Procedure
Write the following MATLAB code in the PC.
1. Discrete time signal.

close all; %to close the figures


clear all; %to clear workspace
clc; %to clear command window

%generation of unit impulse sequence


n=-5:1:5; %to construct independent variable
and determine step size
y=(n==0); %to construct dependent variable
subplot(2,3,1); %to add subplots to a figure
stem(n,y,'r'); %to plot discrete sequence data
legend('Unit impluse sequence'); %to graph legend for lines and
patches
xlabel('Sample(n)'); %to label x-axis
ylabel('Amplitude(V)'); %to label y-axis
grid; %to construct gridlines on a graph

%generation of unit step sequence


n=-5:1:5; y=(n>=0);
subplot(2,3,2); stem(n,y);
legend('Unit step sequence'); xlabel('Sample(n)');
ylabel('Amplitude(V)'); grid;

%generation of ramp sequence


n=0:1:5; y=n;
subplot(2,3,3); stem(n,y,'r');
legend('Ramp sequence'); xlabel('Sample(n)');
ylabel('Amplitude(V)'); grid;

%generation of exponential sequence


n=0:1:20; y=exp(-0.3*n);
subplot(2,3,4); stem(n,y,'m');
legend('Exponential sequence'); xlabel('Sample(n)');
ylabel('Amplitude(V)'); grid;

%generation of sinusoidal sequence


n=0:1:20; y=sin(2*pi*n);
subplot(2,3,[5,6]); stem(n,y);
legend('Sinusoidal sequence'); xlabel('Sample(n)');
ylabel('Amplitude(V)'); grid;
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

1 1 5
Ramp sequence
0.8 0.8 4
Unit impluse sequence Unit step sequence
Amplitude(V)

Amplitude(V)

Amplitude(V)
0.6 0.6 3

0.4 0.4 2

0.2 0.2 1

0 0 0
-5 0 5 -5 0 5 0 1 2 3 4 5
Sample(n) Sample(n) Sample(n)

-15
x 10
1 5

0.8
0
Exponential sequence
Amplitude(V)

Amplitude(V)

0.6
-5
0.4
Sinusoidal sequence

-10
0.2

0 -15
0 5 10 15 20 0 2 4 6 8 10 12 14 16 18 20
Sample(n) Sample(n)

Figure (1): Discrete time signals.

2. To generate continuous time signal repeat previous program and use plot function
instead of stem function.

close all;
clear all;
clc;

%generation of unit impulse signal


n=-5:0.0001:5; y=(n==0);
subplot(2,3,1); plot(n,y,'r');
legend('Unit impluse signal'); xlabel('Time(S)');
ylabel('Amplitude(V)'); grid;

%generation of unit step signal


n=-5:0.0001:5; y=(n>=0);
subplot(2,3,2); plot(n,y);
legend('Unit step signal'); xlabel('Time(S)');
ylabel('Amplitude(V)'); grid;

%generation of ramp signal


n=0:0.0001:5; y=n;
subplot(2,3,3); plot(n,y,'r');
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

legend('Ramp signal'); xlabel('Time(S)');


ylabel('Amplitude(V)'); grid;

%generation of exponential signal


n=0:0.0001:20; y=exp(-0.3*n);
subplot(2,3,4); plot(n,y,'m');
legend('Exponential signal'); xlabel('Time(S)');
ylabel('Amplitude(V)'); grid;

%generation of sinusoidal signal


n=0:0.0001:20; y=sin(2*pi*n);
subplot(2,3,[5,6]); plot(n,y);
legend('Sinusoidal signal'); xlabel('Time(S)');
ylabel('Amplitude(V)'); grid;

1 1 5

0.8 0.8 4
Unit impluse signal Unit step signal Ramp signal
Amplitude(V)

Amplitude(V)

Amplitude(V)
0.6 0.6 3

0.4 0.4 2

0.2 0.2 1

0 0 0
-5 0 5 -5 0 5 0 1 2 3 4 5
Time(S) Time(S) Time(S)

1 1

0.8
0.5
Exponential signal
Amplitude(V)

Amplitude(V)

0.6
0
0.4

-0.5
0.2
Sinusoidal signal

0 -1
0 5 10 15 20 0 2 4 6 8 10 12 14 16 18 20
Time(S) Time(S)

Figure (2): Continuous time signals.

➢ Discussion
1. Modify program to generate:
1.1 A delayed unit sample sequence with a delay of (15) samples.
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

n=-1:1:16; x=((n-15)==0);
stem(n,x,'r'); legend('Unit impluse sequence');
xlabel('Samples(n)'); ylabel('Amplitude(V)');
grid;
ylim([-0.5 1.5]); %to control the upper and lower of y-axis
limits on a graph

1.5

Unit impluse sequence

1
Amplitude(V)

0.5

-0.5
-2 0 2 4 6 8 10 12 14 16
Samples(n)

1.2 A delayed unit step sequence with an advance of (15) samples.

n=-16:1:2; x=((n+15)>=0);
stem(n,x); legend('Unit step sequence');
xlabel('Samples(n)'); ylabel('Amplitude(V)');
ylim([-0.5 1.5]); grid;
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

1.5
Unit step sequence

1
Amplitude(V)

0.5

-0.5
-16 -14 -12 -10 -8 -6 -4 -2 0 2
Samples(n)

1.3 An exponential sequence with a=1.2.

n=0:1:20; x=exp(1.2*n);
stem(n,x,'r'); legend('Exponential sequence');
xlabel('Sample(n)'); ylabel('Amplitude(V)');
grid; axis([-1 21 -0.5e10 3.5e10]);

10
x 10
3.5
Exponential sequence

2.5

2
Amplitude(V)

1.5

0.5

-0.5
0 2 4 6 8 10 12 14 16 18 20
Sample(n)
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

1.4 A sinusoidal sequence of frequencies 0.8, 1.5 & 4.

%generate sinusoidal sequence with frequency=0.8


n=0:1:7; x=sin(0.8*n);
subplot(2,2,1); stem(n,x,'r');
legend('Sinusoidal sequence with 0.8'); xlabel('Sample(n)');
ylabel('Amplitude(V)'); ylim([-2 2]); grid;

%generate sinusoidal sequence with frequency=1.5


x=sin(1.5*n); subplot(2,2,2);
stem(n,x,'k'); legend('Sinusoidal sequence with 1.5');
xlabel('Sample(n)'); ylabel('Amplitude(V)');
ylim([-2 2]); grid;

%generate sinusoidal sequence with frequency=4


x=sin(4*n); subplot(2,2,[3,4]);
stem(n,x,'r'); legend('Sinusoidal sequence with 4');
xlabel('Sample(n)'); ylabel('Amplitude(V)');
ylim([-2 2]); grid;

2 2

1 1
Amplitude(V)

Amplitude(V)

0 0

-1 -1
Sinusoidal sequence with 0.8 Sinusoidal sequence with 1.5
-2 -2
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
Sample(n) Sample(n)

1
Amplitude(V)

-1
Sinusoidal sequence with 4

-2
0 1 2 3 4 5 6 7
Sample(n)
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

2. Sketch the discrete-time sequence x[n] specified by:


𝑥[𝑛] = 2𝛿[𝑛] + 3𝛿[𝑛 − 1] − 5𝛿[𝑛 − 3]

n=-1:1:4; x=(2*(n==0))+(3*((n-1)==0))-(5*((n-3)==0));
stem(n,x,'r'); legend('x[n] sequence');
xlabel('Sample(n)'); ylabel('Amplitude(V)');
ylim([-6 4]); grid;

4
x[n] sequence
3

0
Amplitude(V)

-1

-2

-3

-4

-5

-6
-1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4
Sample(n)

3. Generate and display a random signal of length 100 with elements uniformly distributed
in interval [-2,2] is given below along with the plot of the random sequence generated.

n=0:1:99; rand(a,b) function generates matrix with


x=4*(rand(length(n),1)-0.5); random values ranging from (0) to (1) and by
stem(n,x,'r'); subtracting its lowest values it produces from
legend('Uniform random sequence'); (0.5) the result will be (-0.5) and multiplying
xlabel('Sample(n)'); the result by (4) it will give the result (-2),
ylabel('Amplitude(V)'); which represents the lower bound for the
ylim([-3 3]); given period in the question, and also same
grid; process for the upper bound.
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

Uniform random sequence

1
Amplitude(V)

-1

-2

-3
0 10 20 30 40 50 60 70 80 90 100
Sample(n)

4. Generate and plot of a ramp sequence r[n-5].

n=-1:1:10; x=(n-5).*((n-5) >=0);


stem(n,x); legend('r[n-5] sequence');
xlabel('Sample(n)'); ylabel('Amplitude(V)');
ylim([-1 6]); grid;

6
r[n-5] sequence

4
Amplitude(V)

-1
-2 0 2 4 6 8 10
Sample(n)
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

5. Sketch the discrete-time exponential sequence given by:


𝑥[𝑛] = (0.8)𝑛 𝑢[𝑛]

n=-5:1:20; x=(0.8.^n).*(n>=0);
stem(n,x); legend('r[n-5] sequence');
xlabel('Sample(n)'); ylabel('Amplitude(V)');
ylim([-0.5 1.5]); grid;

1.5
r[n-5] sequence

1
Amplitude(V)

0.5

-0.5
-5 0 5 10 15 20
Sample(n)

6. Compare C.T.S & D.T.S.

Subject C.T.S D.T.S


Label Continuous-Time signal Discrete-Time signal
It’s the variation in the quantity or It’s the variation in the quantity or
Definition signal according to every moment signal according to specific
in specific or infinite time. moments in time called samples.
Independent (t) refer to time. [n] refer to sample, where “n” is
variable integer number.
Time 𝑓𝑟𝑜𝑚 − ∞ 𝑡𝑜 ∞ Specific moments
Digital Signal Processing Laboratory I 2023-2022 EXP.NO.1-PART(I): Generation Discrete Signals

Subject C.T.S D.T.S


Amplitude Continuous or discrete
It provides a lot of bandwidth in the
It provides representation of signal channel and the power of
Advantages in every moment and it cheap. transmitted signal because don’t
work along the time and reduce the
noise that are occur due to C.T.S.
It consumes a lot from bandwidth It doesn’t provide representation of
Disadvantages and power and difficult signal in every moment and it
implementation on it. expensive.
Application Modulation, microphone Digital signal and processing it
Representation For natural signal For continuous signal

Graph

7. Define stem and plot.


▪ Stem: It's an instruction used in the MATLAB to represent and plot the discrete-time
signal. The syntax as (n,x), where “x” is refer to dependent variable and “n” is refer to
independent variable.

▪ Plot: It's an instruction used in the MATLAB to represent and plot the continuous-
time signal. The syntax as (t,x), where “x” is refer to dependent variable and “t” is
refer to independent variable.

You might also like