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

Quantization of Continuous Time Domain Signal in MATLAB

This document discusses quantizing a continuous time domain signal in MATLAB in 3 tasks: 1) It generates a 2000Hz sinusoidal signal over 10 periods and plots it 2) It samples the signal at 20 times the frequency and plots the sampled signal 3) It quantizes the sampled signal values to the nearest of 8 levels and plots the quantized signal

Uploaded by

Shahid Rasool
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Quantization of Continuous Time Domain Signal in MATLAB

This document discusses quantizing a continuous time domain signal in MATLAB in 3 tasks: 1) It generates a 2000Hz sinusoidal signal over 10 periods and plots it 2) It samples the signal at 20 times the frequency and plots the sampled signal 3) It quantizes the sampled signal values to the nearest of 8 levels and plots the quantized signal

Uploaded by

Shahid Rasool
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Quantization of Continuous Time Domain Signal in MATLAB

Note: There is only one code which is divided into 3 sub-codes to demonstrate each task. Each code
requires preceding code to execute.

Task 1

Code
close all;
clear all;
clc
f = 2000; %frequency of signal = 2000Hz
T = 1/f; %time period of signal
tmin = 0;
tmax = 10*T; %gives 10 cycles
dt = T/100; %time spacing
t = tmin:dt:tmax;
x = 8*sin(2*pi*f*t); %signal
figure(1)
plot(t,x);
xlabel('Time (s)')
ylabel('Amplitude (V)')
grid on;
Output
8

2
Amplitude (V)

-2

-4

-6

-8
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (s) -3
x 10

Task 2

Code
fs=20*f; %sampling frequency
ts=1/fs;
N=length(t);
n=0:(N-1)/5; %samples array
xs = 8*sin(2*pi*f*n*ts); %sampled signal
figure(2)
stem(n,xs);
grid on;
Output

X= 24
Y= 7.6085

6 X= 23
Y= 6.4721

X= 22
4 Y= 4.7023

2 X= 21
Y= 2.4721
Amplitude (V)

-2

-4

-6

-8
0 20 40 60 80 100 120 140 160 180 200
Samples (No of sample)
Task 3

Code
Q = 8; %quantization levels is 2Q
N = length(xs);
d = max(abs(xs))/Q; %length of quantile interval
for k = 1:N
if(abs(xs(k)-ceil(xs(k)))>(d/2))
y(k)=floor(xs(k))
else y(k)=ceil(xs(k))
end
end
stem(n,y,'r')
xlabel('Samples (No of sample)')
ylabel('Quantized Values (V)')
grid on;

Output

8
X= 24
Y= 8

6
X= 23
Y= 6
X= 22
4 Y= 5

2
Quantized Values (V)

X= 21
Y= 2

-2

-4

-6

-8
0 20 40 60 80 100 120 140 160 180 200
Samples (No of sample)

You might also like