0% found this document useful (0 votes)
6 views24 pages

LAB Tasks Noor

Uploaded by

noorelahibajwa2
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)
6 views24 pages

LAB Tasks Noor

Uploaded by

noorelahibajwa2
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/ 24

Digital Signal Processing 2022F-BEL-029

Lab # 1
REVIEW OF MATLAB FUNDAMENTALS

OBJECTIVE:
1. Review of basic commands in MATLAB.
2. Investigate the difference between different mathematical operations. 3.
Generate complex-valued matrix
4. Implementation of function.
5. Review of Simulink

TASK 1 : Try all helpmethodsto gethelpof anyfunction.

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

TASK 2:
a) Assign 10 samples, from 0 to 9, of time to the vector t.

t=

[0:9] t

0 1 2 3 4 5 6 7 8 9

(b) Assign a vector of samples without assigning it to a variable.


[0:9]

ans =

0 1 2 3 4 5 6 7 8 9

(c)Assign 10 samples, from 0 to 9, of time to any vector without printing it to


screen.

t = [0:7}

Task # 3
Investigate the difference between multiplication*and element‐wise multiplication.*
of vectors/matrices.

a = [1 2 ; 3 4] a =

1 2
3 4

>> b = [5 6 ; 7 8]
b =

5 6
7 8

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

>> c =

a*b c =

19 22
43 50

>> d =

a.*b d =

5 12
21 32

Task # 4: Generate a complex‐valued matrix a = ones (1,10)+i* (1 : 10) and


calculate the absolute square of all elements of this matrix.

a = ones(1,10)+i*(1:10)

a=

Columns 1 through 4

1.0000 + 1.0000i1.0000 + 2.0000i1.0000 + 3.0000i1.0000 + 4.0000i

Columns 5 through 8

1.0000 + 5.0000i1.0000 + 6.0000i1.0000 + 7.0000i1.0000 + 8.0000i

Columns 9 through 10

1.0000 + 9.0000i1.0000 +10.0000i

TASK#5: Implement a function


[x]=sinewave(t)
Which produces a sine wave of 1001 samples with spacing of At=1ms and construct
the output.
function x = sin(t)

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

f = 1; % Frequency in Hz x = sin(2 * pi
* f * t); stem(t, x) title('Sine Wave')
xlabel('Time (s)') % Added xlabel for
clarity ylabel('Amplitude') % Added
ylabel for clarity grid on
end

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Task #6:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

TASK#7: a) Using Simulink, plot a sine wave between t=0s and t=10s.

b) Using simulink, plot a sine wave between t=0s and t=100s

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Task # 8: Using Simulink, construct a unit step signal between t=0s and t=10s

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

y(t) = 0.2x(t) +0.8x(t ‐2)‐0.4x(t ‐5) Simulate the system between t=0s and t=10s
Task#9: Implement the following continuous‐time system with a Simulink model:

with the following inputs: a) x(t) = u(t) (Unit step) b) x(t) = 2.5 sin(2*pi*f*t)

Conclusion: This lab enhanced our MATLAB and Simulink skills by reviewing
essential commands and mathematical operations. We created a complex-valued
matrix, developed a custom function, and explored Simulink for modeling dynamic
systems. These activities provided valuable insights into digital signal processing,
deepening our understanding of analyzing and simulating real-world signals.

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Lab # 2

EFFECTS OF SAMPLING ON ANALOG SIGNALS

OBJECTIVE:
1. To observe the effects of sampling on continuous time signals.
2. Conversion of continuous time signal to discrete time signal.
3. Observe the effects of sampling theorem on discrete time signals by changing
their sampling frequencies.

Task#1: Write a script to generate a continuous time sinusoid signal with


amplitude=2 for a time t and take the frequency as a user input by using input
command.

f = input('enter value of
frequency'); t=0:0.001:0.02; x
= 2*sin(2*3.142*f*t);
subplot(2,1,1) plot(t,x)
subplot(2,1,2) stem(t,x)

Command Window >>


Noor enter value of
frequency50
>> Noor enter value
of frequency10
>> Noor enter value
of frequency50
>>

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Task#2: Write a script to convert continuous time signal of task #1 to a discrete


time signal and take the analog frequency as input. Sampling frequency should be
less than twice of analog signal frequency in Hertz.

f = input('enter value of
frequency'); t=0:0.001:0.04; x
= 2*cos(2*3.142*f*t);
subplot(3,1,1) plot(t,x) fs =
f/2; n = 0:1/fs:2/f;
b=2*cos(2*3.142*f*n);
subplot(3,1,2) stem(t,x)
subplot(3,1,3) stem(n,b)

Command Window >>


Noor enter value of
frequency10
>> Noor enter value
of frequency50
>> Noor enter value of
frequency100

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Task#3: Write a script to convert continuous time signal of task#1 to a discrete


time signal and take the analog frequency as input. Sampling frequency should be
equal to twice of analog signal frequency in Hertz.

f = input('enter value of
frequency'); t=0:0.001:0.20; x
= 2*cos(2*3.142*f*t);
subplot(3,1,1) plot(t,x) fs =
2*f; n = 0:1/fs:2*f;
b=2*cos(2*3.142*f*n);
subplot(3,1,2) stem(t,x)
subplot(3,1,3) stem(n,b)

Command Window >>


Noor enter value of
frequency100
>> Noor enter value of
frequency100
>> Noor enter value
of frequency50

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

TASK#4: Write a script to construct continuous time signal of task # 1 to a discrete


time signal and take the analog frequency as input. Sampling frequency should be
greater than twice of analog signal frequency in Hertz.

Code: a =2; fa = input('Enter the


value of frequency :'); fs = 4*fa; n =
0:1/fs:1; x = a*cos(2*pi*fa*n);
stem(n,x)

Task#5: Write a script using subplot command to generate task #1, task#2, task#3
and task#4plots. Analyze the four plots, what happens by increasing the sampling
frequency?
% Main script to generate plots for Task #1, Task #2, Task #3, and Task #4

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

a =2; fa = input('Enter the value of


frequency :'); t=0:0.001:2/fa; n =
0:1/fs:1; x = a*cos(2*pi*fa*t); fs =
fa/2; n = 0:1/fs:2/fa; b =
a*cos(2*pi*fa*n); fs1 = 2*fa; n1 =
0:1/fs1:2/fa; b1 = a*cos(2*pi*fa*n1);
fs2 = fa*20; n2 = 0:1/fs2:2/fa; b2 =
a*cos(2*pi*fa*n2); subplot(4,1,1)
stem(t,x) subplot(4,1,2) stem(n,b)
subplot(4,1,3) stem(n1,b1)
subplot(4,1,4) stem(n2,b2)
Command Windows
Enter the value of
frequency :50 >> noor
Results:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Conclusion: In this lab, this experiment highlighted the impact of sampling on


continuous-time signals, demonstrated the conversion to discrete-time signals, and
explored how variations in sampling frequencies affect these discrete signals.

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Lab # 3a

ALIASING EFFECT IN ANALOG SIGNALS

OBJECTIVE:

1. Plot two continuous-time signals of 10 Hz and 110 Hz.


2. Sample at Fs = 100 Hz.
3. Analyze the effect of aliasing by plotting both signals in discrete form.
4. Plot discrete-time signals with different frequencies and analyze the
similarities and differences.

EXERCISE:

Task #1: Plot two CT signals of 10 Hz and 110 Hz for 0 < t < 0.2 secs. Sample at Fs
= 100 Hz and plot them in discrete form.

Coding:
f1 = 10
f2 =110; fs = 100; t = 0:0.001:0.2; x1 =
sin(2*pi*f1*t); x2 = sin(2*pi*f2*t); plot(t,x1,t,x2)
n1 = 0: 1/fs: 2/f1; n2 = 0:1/fs: 11/f2; y1 =
sin(2*pi*f1*n1); y2 = sin(2*pi*f2*n2)
subplot(3,1,2); stem(n1,y1); subplot(3,1,3);
stem(n2,y2); Result:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Task #2(a) For a C.T signal x=sin(2πft)


Plot the signal x(n) for n=0 to 99 for f=[500 2000 3000 4500] sampled at
fs=5000hz.
● Plot the signal x(n).
● Plot the signal x(n) created by even number samples of x(n)

Coding:

n = 0:99; fs = 5000;
for i = 1:4 f = [500
2000 3000 4500 ]
x = sin(2*pi*f(i)*n/fs);
subplot(4,1,i) stem (n,x) end

Result:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Task #2(b)
Suppose that f=2khz & fs = 50khz
1. 1) plot the signal x(n)
2. 2)plot the signal x(n) created by even number samples of x(n)

Coding: n = 0:99; f
=2000 fs = 50000; for
i = 1:4 f = [500 2000
3000 4500 ]
x = sin(2*pi*f(i)*n/fs);
subplot(4,1,i) stem (n,x) End

Result:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Conclusion:
In this lab, I observed how aliasing occurs when continuous signals are sampled
below the Nyquist frequency, causing higher frequencies to be misrepresented as
lower ones. By comparing discrete-time signals at different sampling rates, I learned
the importance of choosing an appropriate sampling rate to preserve signal
accuracy and prevent distortion.

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

Lab # 3b

EFFECTS OF QUANTIZATION ON DISCRETE TIME CONTINUOUS SIGNALS

OBJECTIVE:
● Simulate a discrete-time continuous sinusoid signal with length of the signal
be500.
● Choose the significant digits for round-off and apply to the signal above.
● Compute error signals and SQNR.
● Now choose significant digits for truncation for the same signal given above.
● Analyze the difference between round-off and truncation.

TASK#1: Differentiate between mind off and tnmcation and also use MATLAB
help to get familiar with the syntax of both method

In a numerical computation, each number must be rounded to a certain number of


digits. On this fact, round- off error depends. It is caused by truncating a
mathematical procedure.
At the finite process replaces infinite one, truncation errors. Approximating
mathematical procedures cause this error. It has two types in case of numerical
integration, these are global and local truncation errors.

Round off:

help round round rounds towards near—st


decimal or

round (X) rounds —ach element af X to the nearest integer .

round (X, N), far positive integers N, rounds to N digits to the right
o
of the decimal point. If N is zero, X is round—cl to the nearest
integer.
If N is less than X is rounded Of point.
N must be a scalar integer.

round (X, N, 'significant') rounds each Element to its N mast


significant digits, counting from the most—significant or Left side oof
the nurrber . N must be a positive integer scalar .

Tnmcate :
>> help fix fix Round
towards zero.

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

fix (X) rounds the elements of X to the nearest integers


towards zero.

TASK 02: Simulate a discrete time continuous valued (DTCV) sinusoid of 1/50
cycles/sample with length of the signal to be 500 & choose the no. of significant
digits for round‐off and apply to the signal generated above. Compute the error
signals and SQNR.

CODING:

fs=1000;
fa=20;
N=500;
n_bits=input('Enter no. of bits:');
n=0:N-1; x=sin(2*pi*fa*n/fs);
x_quant=round(x*2^(n_bits-1))/2^(n_
bits-1); e_quant=x-x_quant;
sqnr=10*log10(sum(x.^2)/sum(e_qua
nt.^2)); subplot(3,1,1) plot(n,x);
subplot(3,1,2) plot(n,x_quant);
subplot(3,1,3) plot(n,e_quant);

Command Window

Results:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

TASK 03: For F = 1/50 and length of the signal to be 200, write a program to
quantize the signal x (n), using Truncation. Also increase the number of levels by
increasing the amplitude of the signal. Plot the signals x (n), xq (n) and eq (n) and
also compute the corresponding SQNR.

CODING:

fs=1/50; N=500; n=0:499;


q=input('Enter Rounding Off
Digits:'); x=sin(2*pi*fs*n);
xq=round(x,q); xe=x-xq;
subplot(2,1,1) stem(n,xq)
Px=(1/N)*sum(x.*x);
Pq=(1/N)*sum(xe.*xe);
sqnr=10*(Px/Pq); subplot(2,1,2)
stem(n,xe)

Command Window:

Results:

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

TASK 04: Use round off method by using a for loop and take significant digits as
input i.e. 1, 2 & 3. In each case plot the signals x (n), xq(n) and eq(n) and also
compute the corresponding SQNR.

CODING:

n=0:99; x=sin(2*pi*0.1*n);
sd=[1,2,3]; for i=1:length(sd)
xq=round(x); eq=x-xq;
sqnr=10*log10(sum(x.^2)/sum(e
q.^2)); subplot(3,1,1); plot(n,x);
title('Original Signal x(n)');
subplot(3,1,2); plot(n,xq);
title('Quantized Signal (xq)');
subplot(3,1,3); plot(n,eq);
title('Quantization Error (eq)');
end
Results:

Conclusion:
In this lab, we created a specialized input program that applies the Truncation
method to determine the quantization length from discrete-time, continuous-valued

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering
Digital Signal Processing 2022F-BEL-029

(DTCV) signals. This method improves signal processing accuracy and delivers more
reliable, consistent results.

Sir Syed University of Engineering & Technology,


Karachi Department of Electrical Engineering

You might also like