필터 지우기
필터 지우기

Pulse Code Modulation and Demodulation

조회 수: 261 (최근 30일)
Saad Rana
Saad Rana 2020년 12월 27일
댓글: Sushilkumar 2024년 5월 6일
I have written a code to do Pulse Code Modulation but I am unable to retrieve the message signal back. Can someone please help me write demodulation code.
Here is what I have written for modulation
time = 0:0.0001:20;
const = input('Enter Bit Depth of PCM Coding:');
part = -1:0.1:1;
codebook = -1:0.1:1.1;
msg = sin(time);
[indx,quants] = quantiz(msg,part,codebook);
subplot(3,1,1);
plot(time,msg);
title('Message Signal');
subplot(3,1,2);
plot(time,quants);
title('Quantized Signal');
y = uencode(quants,const);
ybin = dec2bin(y,const);
subplot(3,1,3);
plot(time,y);
title('PCM PLOT');
How can I convert back the modulated signal to original.
  댓글 수: 1
Sushilkumar
Sushilkumar 2024년 5월 6일
% Define the analog signal
t = 0:0.001:1; % Time vector from 0 to 1 second
Analog_Signal = sin(2*pi*5*t); % Example analog signal (sine wave)
% PCM parameters
bit_depth = 8; % Number of bits for quantization
quantization_levels = 2^bit_depth; % Total quantization levels
% Quantization
Quantized_Signal = round((Analog_Signal + 1) * (quantization_levels - 1) / 2);
% Demodulation
Demodulated_Signal = (2 * Quantized_Signal) / (quantization_levels - 1) - 1;
% Encoding PCM
Encoded_PCM = de2bi(Quantized_Signal, bit_depth, 'left-msb');
% Plotting
subplot(4,1,1);
plot(t, Analog_Signal);
title('Analog Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(4,1,2);
stairs(t, Quantized_Signal);
title('Quantized Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(4,1,3);
plot(t, Demodulated_Signal);
title('Demodulated Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(4,1,4);
plot(t, Encoded_PCM);
title('Encoded PCM');
xlabel('Time');
ylabel('Bit');

댓글을 달려면 로그인하십시오.

채택된 답변

Darel
Darel 2022년 6월 3일
If the bit depth is reasonably large (say const = 8), then you can get back the uencoded signal with udecode:
newquants = udecode(y, const)
max(abs(quants(:) - newquants(:)))
One other thing about this code is that the quantiz function could be configured better. The "codebook" entry for quantiz provides the values assigned to represent input numbers that fall within each quantization bin. So you probably want to select values that represent the center of the bins, not the endpoints. Note also that the first and last entries represent values that fall outside the total range. So a better setting for "codebook" would be
codebook = [-10, -.95:0.1:.95, 10];

추가 답변 (4개)

Asmita Jangam
Asmita Jangam 2021년 5월 8일
c=input('Enter Bit Depth Of PCM Coding:');

Avinash
Avinash 2023년 3월 27일
PCM Modulation and Demodulation using Trainer Kit and MATLAB

mohan
mohan 2023년 4월 4일
time = 0:0.0001:20;
const = input('Enter Bit Depth of PCM Coding:');
Error using input
Support for user input is required, which is not available on this platform.
part = -1:0.1:1;
codebook = -1:0.1:1.1;
msg = sin(time);
[indx,quants] = quantiz(msg,part,codebook);
subplot(3,1,1);
plot(time,msg);
title('Message Signal');
subplot(3,1,2);
plot(time,quants);
title('Quantized Signal');
y = uencode(quants,const);
ybin = dec2bin(y,const);
subplot(3,1,3);
plot(time,y);
title('PCM PLOT');

Sudarshan
Sudarshan 2023년 7월 16일
편집: Walter Roberson 2024년 5월 3일
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
Error using input
Support for user input is required, which is not available on this platform.
n1=input('Enter number of samples in a period : ');
L=2^n;
% % Signal Generation
% x=0:1/100:4*pi;
% y=8*sin(x); % Amplitude Of signal is 8v
% subplot(2,2,1);
% plot(x,y);grid on;
% Sampling Operation
x=0:2*pi/n1:4*pi; % n1 nuber of samples have tobe selected
s=8*sin(x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Sinal'); ylabel('Amplitude--->'); xlabel('Time--->');
% Quantization Process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized valuses
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Encoding Process
figure
code=de2bi(ind,'left-msb'); % Cnvert the decimal to binary
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j); % convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stairs(coded); % Display the encoded signal
axis([0 100 -2 3]); title('Encoded Signal');
ylabel('Amplitude--->');
% Demodulation Of PCM signal
qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb'); % Getback the index in decimal form
q=del*index+vmin+(del/2); % getback Quantized values
subplot(2,1,2); grid on;
plot(q);
% Plot Demodulated signal
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

카테고리

Help CenterFile Exchange에서 PCM에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by