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

DC 2

The document contains MATLAB code for generating and processing an analog signal, including sampling, quantization, encoding, and demodulation. It prompts the user for the maximum amplitude and number of bits, then visualizes the analog, sampled, quantized, and demodulated signals through various plots. An error is encountered when attempting to use the input function within the script.

Uploaded by

Prashanna Yadav
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

DC 2

The document contains MATLAB code for generating and processing an analog signal, including sampling, quantization, encoding, and demodulation. It prompts the user for the maximum amplitude and number of bits, then visualizes the analog, sampled, quantized, and demodulated signals through various plots. An error is encountered when attempting to use the input function within the script.

Uploaded by

Prashanna Yadav
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; close all; clear all;

vmax = input('Enter the maximum Amplitude: ');


n = input('Enter the value of number of bits: ');
n1 = 50;

x = 0 : (2 * pi / n1) : 4 * pi;
s = 8 * sin(x);

subplot(3,1,1);
plot(s);
grid on;
title('Analog Signal');
ylabel('Amplitude');
xlabel('Time');

subplot(3,1,2);
stem(x, s);
grid on;
title('Sampled Signal');
ylabel('Amplitude');
xlabel('Time');

L = 2^n;
del = (2 * vmax)/L;
vmin = -vmax;
part = vmin+del: del:vmax-del;
code = vmin + (del/2): del: vmax - (del/2);
[ind, q] = quantiz(s, part, code);
subplot(3,1,3);
stem(x, q);
grid on;
title('Quantized Signal');
ylabel('Amplitude');
xlabel('Time');

figure
code1 = de2bi(ind, 'left-msb');
k = 1;
l1 = length(ind);
for i = 1:l1
for j = 1:n
coded(k) = code1(i,j);
j = j + 1;
k = k + 1;
end
i = i + 1;
end
subplot(2,1,1);
stairs(coded);
grid on;
axis([0 100 -0.5 1.5]);
title('Encoded Signal');

1
ylabel('Amplitude')
xlabel('Time');

qunt = reshape(coded, n , length(coded)/n);


index = bi2de(qunt','left-msb');
q = del*index+vmin+(del/2);
subplot(2,1,2);
grid on;
plot(q);
grid on;
title('Demodulated Signal');
ylabel('Amplitude');
xlabel('Time');

Error using input


Cannot call INPUT from EVALC.

Error in dc2 (line 2)


vmax = input('Enter the maximum Amplitude: ');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Published with MATLAB® R2024b

You might also like