Plotting a equally distributed quantized signal

In MATLAB, quantize the following composite signal in 8 equally distributed levels and show only 4 cycles.
x=91*sin(2*pi*369*t)+36*sin(2*pi*919*t+pi/3)+69*sin(2*pi*183*t+2*pi/3)

 Réponse acceptée

Yazan
Yazan le 3 Juil 2021
% sinusoids in the signal
f1 = 369;
f2 = 919;
f3 = 183;
% max and min spectral components
fmax = max([f1, f2, f3]);
fmin = min([f1, f2, f3]);
% sampling freq = 10 times the largest spectral component
fs = 10*fmax;
% show 4 cycles
T = 1/fmin*4;
% time axis
t = 0:1/fs:T-1/fs;
% signal
x = 91*sin(2*pi*f1*t) + 36*sin(2*pi*f2*t+pi/3) + 69*sin(2*pi*f3*t+2*pi/3);
% plot signal
figure, plot(t, x, 'LineWidth', 1), hold on, grid minor
% 8 levels of quantization
ql = 8;
% find the levels
th = linspace(min(x), max(x), ql);
% quantize the signal
xdif = abs(x-th');
[idx, ~] = ind2sub(size(xdif), find(xdif == min(xdif)));
xq = th(idx);
% plot quantized signal
plot(t, xq, '--g', 'LineWidth', 1.5);
legend({'Original signal', 'Quantized signal'}, 'Location', 'best');
hold off

2 commentaires

In the output, quantized signal is not showing.
This is because you're using an old version of Matlab. Replace line 23 with the following
xdif = abs(repmat(x, [ql,1])-repmat(th',[1, size(x,2)]));

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Signal Processing Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by