Plotting a equally distributed quantized signal

6 Ansichten (letzte 30 Tage)
S.M. Masudur Rahman
S.M. Masudur Rahman am 3 Jul. 2021
Kommentiert: Yazan am 3 Jul. 2021
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)

Akzeptierte Antwort

Yazan
Yazan am 3 Jul. 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 Kommentare
S.M. Masudur Rahman
S.M. Masudur Rahman am 3 Jul. 2021
In the output, quantized signal is not showing.
Yazan
Yazan am 3 Jul. 2021
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)]));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by