Plotting a equally distributed quantized signal

6 次查看(过去 30 天)
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)

采纳的回答

Yazan
Yazan 2021-7-3
% 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 个评论
Yazan
Yazan 2021-7-3
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)]));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Source Coding 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by