How to plot quantized signal in MATLAB?

24 views (last 30 days)
ABTJ
ABTJ on 26 Feb 2021
Answered: Mathieu NOE on 2 Mar 2021
During the process of analog to digital conversion Some time it is needed to plot quantized signal
Which command(s) can be used for plotting a quantized signal?

Answers (1)

Mathieu NOE
Mathieu NOE on 2 Mar 2021
hello
this little code snipset to illustrate what is sampling
quantization is simply to round the y values to the nearest 2^(n-1) value, (n = nb of bits of the ADC)
%Time Base
Fs = 1000;
dt = 1/Fs;
t = 0:dt:1.8;
samples = length(t);
%Sine Frequencies
Fn1 = 1;
Fn2 = 6;
signal = sin(2*pi*Fn1*t) + 0.25*sin(2*pi*Fn2*t);
% decimated signal for tem plot
decim = 50; % decimation factor
ind = (1:decim:samples);
t2 = t(ind);
x2 = signal(ind);
%Second Part
h = stem(t2, x2, 'linewidth', 2);
hold
plot(t, signal, 'linewidth', 2)
lgd = legend('Discrete Data', 'Continuous Data');
set (lgd, "fontsize", 12)
set(gca,'XTick',[0:0.2:1.8]);
set(gca,'YTick',[-2:0.5:2]);
title('Time vs Magnitude','fontweight','bold','fontsize',16);
xlabel('Time(s)','fontweight','bold','fontsize',14)
ylabel('Magnitude','fontweight','bold','fontsize',14)
grid

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!