0% found this document useful (0 votes)
14 views

Lab Sheet 1

Uploaded by

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

Lab Sheet 1

Uploaded by

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

Nepal Engineering College

(Affiliated to POKHARA UNIVERSITY)


Changunarayan, Bhaktapur

Report On
FAMILIARIZATION WITH BASIC DISCRETE-TIME SIGNAL.

SUBMITTED BY: SUBMITTED TO:


Name: Ashutosh Acharya Rupesh D. Shrestha Sir
Roll No: 017-311
Department: Computer – 1
Group - A
1.Elementary discrete-time signal Plot the basic discrete-time signal using
MATLAB.
i.Unit Impulse sequence
ii.Unit step sequence
iii.Unit Ramp sequence
Create function m-files of each signals and plot the sequences. Also plot
impulse sequence and ramp sequence using step sequence function and step
sequence using impulse sequence function.
A Unit Impulse
Theory:
A unit impulse sequence is a sequence having unit magnitude at origin and zero
magnitude at all other sample instants.
While coding a impseq function is created and this file is saved as file imseq
and a next file is created where the function is called.
Source Code
#A unit impulse sequence#
#Function part#
function [n, d] = impseq(n0, n1 , k)
n = n0 : n1;
d = (n == k);
end
#Normal Code#
[n, d] = impseq(-3, 4, 2);
stem(n, d);
title('unit impulse sequence 017-311');
xlabel('time');
ylabel('magnitude')

Output:

1
A Step Sequence
Theory:
It is defined as a single valued function of one or more independent variables
which contain some information.
While coding a unitstepseq function is created and this file is saved as file
unitstepseq and a next file is created where the function is called.
Source Code:
#A Unit Step Sequence#
#Function part#
function [n, d] = unitstepseq(n0, n1 , k)
n = n0 : n1;
d = (n > k);
end
#Normal Code#
[n, d] = unitstepseq(-5, 5, 2);
stem(n, d);
title('unit step sequence 017-311');
xlabel('time');
ylabel('magnitude');

Output:

2
A Unit Ramp
Theory:
It is defined as a signal function of one or more independent variables which
contain some information.
While coding a unitrampseq function is created and this file is saved as file
unitrampseq and a next file is created where the function is called.
Source Code:
#A Unit Ramp Sequence#
#Function part#
function [n, d] = unitrampseq(n0, n1 , k)
n = n0 : n1;
unitstep = n>=0;
d = n.*unitstep;
end
#Normal Code#
[n, d] = unitrampseq(-5, 5, 0);
stem(n, d);
title('unit ramp sequence 017-311');
xlabel('time');
ylabel('magnitude')

Output:

3
2.Continuous-time sinusoidal signal Care must be taken while plotting
continuous-time signal in MATLAB because all signals in MATLAB are
discrete-time, but they will look like continuous-time signals if the sampling rate
is much higher than the Nyquist rate. For example, if we wish to plot continuous-
time sinusoid, x(t) = 2piFt+θ we must take sampling frequency, F s ≥ 2F. The
MATLAB code to plot above signal would be:
F = 3; A = 2; th = 0; % Three parameters frequency, amplitude and phase of
sinusoid.
Fs = 10*F; % Taking sampling rate is equal to ten times the frequency.
T = 1/Fs; % Time period of sampled sequence.
t = 0:T:1; % Defining time t from zero to one.
xt = A*cos(2*pi*F*t + th); % Defining the signal x(t)
plot(t,x); % Plotting the signal t Vs x(t)
a.Create and run the m-file above, and produce figure.
b.Change the sampling frequency and study the behavior of sinusoid.
c.Try plotting the signal for different frequencies.

Theory: A continuous time sinusoidal signal is defined as a signal which is

4
defined for every instant of time.

a) solution

Source Code:

#a solution#
F = 3;
A = 2;
th = 0;
Fs = 10*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
plot(t,x);
title('Continious Time Signal CRN : 017311');
xlabel('time');
ylabel('magnitude');

Output:

b) Solution
Source Code:
#b solution#
F = 3;
A = 2;
th = 0;
Fs = 2*F;

5
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(221);
plot(t,x);
title('With Frequency Sample as Fs=2*F CRN :
017311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20)

F = 3;
A = 2;
th = 0;
Fs = 5*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(222);
plot(t,x);
title('With Frequency Sample as Fs=5*F CRN :
017311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20)

F = 3;
A = 2;
th = 0;
Fs = 8*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(223);
plot(t,x);
title('With Frequency Sample as Fs=8*F CRN :
017311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20)

F = 3;
A = 2;
th = 0;
Fs = 12*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);

6
subplot(224);
plot(t,x);
title('With Frequency Sample as Fs=12*F CRN :
017311');
xlabel('time');
ylabel('magnitude');

set(gca, "linewidth", 2, "fontsize", 20)

Output:

c) Solution

Source Code

#c solution#
F = 10;
A = 2;
th = 0;
Fs = 2*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(221);
plot(t,x);
title('With Frequency Sample as F=10 CRN : 017311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20)

7
F = 20;
A = 2;
th = 0;
Fs = 2*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(222);
plot(t,x);
title('With Frequency Sample as Fs=20 CRN : 017311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20)

F = 30;
A = 2;
th = 0;
Fs = 2*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(223);
plot(t,x);
title('With Frequency Sample as F=30 CRN : 017311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20)

F = 40;
A = 2;
th = 0;
Fs = 2*F;
T= 1/Fs;
t = 0:T:1;
x=A*cos(2*pi*F*t+th);
subplot(224);
plot(t,x);
title('With Frequency Sample as F=40 CRN : 017311');
xlabel('time');
ylabel('magnitude');

set(gca, "linewidth", 2, "fontsize", 20)

Output

8
3.Discrete-time sinusoidal signal A discrete-time sinusoidal signal is expressed
as, x(n) = Acos(2pifn +θ ) Where n is an integer variable. Write a MATLAB
program to plot discrete-time sinusoid with frequency f = 0.1. Study the
following properties of discrete-time sinusoidal signal in MATLAB:
i.A discrete-time sinusoid is periodic only if its frequency f is a rational number.
ii.Discrete-time sinusoids whose frequencies are separated by an integer
multiple of 2π are identical.
iii.The highest rate of oscillation in a discrete-time is attained when ω = π.

Theory:

A discrete time sinusoidal is defined as signal which is defined at discrete instant


of time.

i) Solution
Source Code:
#i Solution#
A = 3;
f = 1/8;
n = 1:25;
ph = pi/3;

9
x = A*cos(2*pi*f*n+ph);
stem(n,x);
title('Discrete time sinusoid CRN : 017-311');
xlabel('time');
ylabel('magnitude');

set(gca, "linewidth", 2, "fontsize", 20)

Output:

ii) Solution
Source Code:
#ii Solution#
A = 3;
f = 1/14;
n = 0:60;
ph = 0;
x = A*cos(2*pi*f*n+ph);
subplot(221);
stem(n,x);
title('Discrete time sinusoid for ph = 0 CRN : 017-
311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

ph = 2*pi;
x = A*cos(2*pi*f*n+ph);
subplot(222);
stem(n,x);

10
title('Discrete time sinusoid for ph = 2*piCRN : 017-
311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

ph = 2*2*pi;
x = A*cos(2*pi*f*n+ph);
subplot(223);
stem(n,x);
title('Discrete time sinusoid for ph = 4*pi CRN :
017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

ph = 5*2*pi;
x = A*cos(2*pi*f*n+ph);
subplot(224);
stem(n,x);
title('Discrete time sinusoid for ph = 5*2*pi CRN :
017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

Output:

11
iii) Solution
Source Code:
#iii Solution#
A = 2;
w=pi/2;
n = 0:60;
ph = 0;
x = A*cos(w*n+ph);
subplot(221);
stem(n,x);
title('Discrete time sinusoid for w = pi/2 CRN : 017-
311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

w= pi;
x = A*cos(w*n+ph);
subplot(222);
stem(n,x);
title('Discrete time sinusoid for w = pi CRN : 017-
311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

w = 2*pi/3;
x = A*cos(w*n+ph);
subplot(223);
stem(n,x);
title('Discrete time sinusoid for w = 2*pi/3 CRN :
017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

w = 2*pi;
x = A*cos(w*n+ph);
subplot(224);
stem(n,x);
title('Discrete time sinusoid for w = 2*pi CRN : 017-
311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

12
Output:

4.Fourier series Fourier series theory states that a periodic wave can be
represented as a summation of sinusoidal waves with different frequencies,
amplitudes and phase values.
a.Write a program that plots the signal x(t) for N =9
N
sin 2 pi n t
x (t )= ∑ n
n=1
(n odd)

b.Write a program that plots the signal x(t) in step (a) but with N = 99 and N =
999.
c.What do you conclude from steps (a) & (b)?

a) Solution
Source Code:
#a solution#
t=0:.01:12;
N = 9;
x = 0;

13
for n = 1:2:N
x = x+(sin(2*pi*n*t)/n);
endfor
plot(t,x);
title('Signal x(t) a solution CRN : 017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

Output:

b) Solution
Source Code:
#b solution#
t=0:.01:12;
N = 99;
x = 0;
for n = 1:2:N
x = x+(sin(2*pi*n*t)/n);
endfor
plot(t,x);
title('Signal x(t) when N = 99 CRN : 017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

Output:

14
Source Code:
#b solution#
t=0:.01:12;
N = 999;
x = 0;
for n = 1:2:N
x = x+(sin(2*pi*n*t)/n);
endfor
plot(t,x);
title('Signal x(t) when N = 999 CRN : 017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

Output:

15
c) Solution
By compairing a and b we can see a smooth formation of signal along with
removal of distortion by increasing the value of N

5.Other Signals:A normally distributed random signal of length N can be


generated using the MATLAB command randn(1,N):
a.Write a program to generate a normally distributed random signal of length
100 samples.
b.Write a program to generate noise sinusoidal signal.

a) Solution
Source Code:
#a solution#
stem(randn(1, 100));
title('Randomly Sampled Signal 017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

Output:

16
b) Solution
Source Code:
#b solution#
f = 3;
A = 3;
ph = 0;
Fs = 50 * F;
T=1 / Fs;
t=0 : T : 1;
x = A * cos(2*pi*f*t+ph);
plot(t, x);
noiseAmplitude=2;
nois = x + noiseAmplitude * rand(1, length(x));
plot(t, nois);
title('noise sinusoidal signal 017-311');
xlabel('time');
ylabel('magnitude');
set(gca, "linewidth", 2, "fontsize", 20);

Output:

17

You might also like