0% found this document useful (0 votes)
3 views2 pages

PCM

The document outlines a MATLAB script for generating and processing a sinusoidal signal. It includes steps for sampling, quantizing, and encoding the signal into a Pulse Code Modulation (PCM) binary stream. The script also visualizes the analog, sampled, quantized signals, and the PCM encoded stream using subplots.

Uploaded by

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

PCM

The document outlines a MATLAB script for generating and processing a sinusoidal signal. It includes steps for sampling, quantizing, and encoding the signal into a Pulse Code Modulation (PCM) binary stream. The script also visualizes the analog, sampled, quantized signals, and the PCM encoded stream using subplots.

Uploaded by

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

clc; clc;

clear all; clear all;


close all; close all;

t = 0:0.01:14; t = 0:0.01:14;
f = 1/6; f = 1/6;
x = 10 * sin(2*pi*f*t); x = 10 * sin(2*pi*f*t);

fs = 1; fs = 1;
ts = 0:1:14; ts = 0:1:14;
x1 = 10 * sin(2*pi*f*ts); x1 = 10 * sin(2*pi*f*ts);

L = 16; L = 16;
xmin = -10; xmin = -10;
xmax = 10; xmax = 10;
q = (xmax - xmin) / (L - 1); q = (xmax - xmin) / (L - 1);
quantized_index = round((x1 - xmin) / q); quantized_index = round((x1 - xmin) / q);
quantized = xmin + quantized_index * q; quantized = xmin + quantized_index * q;

n = ceil(log2(L)); n = ceil(log2(L));
pcm_stream = dec2bin(quantized_index, n) - '0'; pcm_stream = dec2bin(quantized_index, n) - '0';

disp('First 10 PCM Encoded Binary Samples:'); disp('First 10 PCM Encoded Binary Samples:');
disp(pcm_stream(1:10,:)); disp(pcm_stream(1:10,:));

subplot(4,1,1); subplot(4,1,1);
plot(t, x, 'LineWidth', 1.5); plot(t, x, 'LineWidth', 1.5);
axis([0 14 -11 11]); axis([0 14 -11 11]);
xlabel('Time'); ylabel('Amplitude'); xlabel('Time'); ylabel('Amplitude');
title('Analog signal - DHRUV CHAUHAN 23001003038'); title('Analog signal - DIVEK 23001003042');
grid on; grid on;

subplot(4,1,2); subplot(4,1,2);
stem(ts, x1, 'filled'); stem(ts, x1, 'filled');
axis([0 14 -11 11]); axis([0 14 -11 11]);
xlabel('Time'); ylabel('Amplitude'); xlabel('Time'); ylabel('Amplitude');
title('Sampled signal - DHRUV CHAUHAN 23001003038''); title('Sampled signal - DIVEK 23001003042');
grid on; grid on;

subplot(4,1,3); subplot(4,1,3);
stem(ts, quantized, 'filled'); stem(ts, quantized, 'filled');
axis([0 14 -11 11]); axis([0 14 -11 11]);
xlabel('Time'); ylabel('Amplitude'); xlabel('Time'); ylabel('Amplitude');
title('Quantized signal – DHRUV CHAUHAN 23001003038'); title('Quantized signal - DIVEK 23001003042');
grid on; grid on;

subplot(4,1,4); subplot(4,1,4);
stairs(reshape(pcm_stream.', 1, []), 'LineWidth', 1.2); stairs(reshape(pcm_stream.', 1, []), 'LineWidth', 1.2);
ylim([-0.2 1.2]); ylim([-0.2 1.2]);
xlabel('Bit Index'); ylabel('Bit Value'); xlabel('Bit Index'); ylabel('Bit Value');
title('PCM Encoded Binary Stream – DHRUV CHAUHAN title('PCM Encoded Binary Stream - DIVEK 23001003042');
23001003038'); grid on;
grid on;

You might also like