LAB Tasks Noor
LAB Tasks Noor
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 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
ans =
0 1 2 3 4 5 6 7 8 9
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
>> c =
a*b c =
19 22
43 50
>> d =
a.*b d =
5 12
21 32
a = ones(1,10)+i*(1:10)
a=
Columns 1 through 4
Columns 5 through 8
Columns 9 through 10
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
Task #6:
TASK#7: a) Using Simulink, plot a sine wave between t=0s and t=10s.
Task # 8: Using Simulink, construct a unit step signal between t=0s and t=10s
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.
Lab # 2
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.
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)
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)
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)
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
Lab # 3a
OBJECTIVE:
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:
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:
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:
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.
Lab # 3b
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
Round off:
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.
Tnmcate :
>> help fix fix Round
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:
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:
Command Window:
Results:
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
(DTCV) signals. This method improves signal processing accuracy and delivers more
reliable, consistent results.