What is wrong with this code, please help!

this is the code to qam modulate a quantized sine wave, for some reason i get only 15 constellation points instead of 16.
==================================================================
t = 0:.001:2*pi; % Times at which to sample the sine function
sig = sin(2*t); % Original signal, a sine wave
partition = [-1:2/15:1]; % Length 16, to represent 17 intervals
codebook = [0:1:16]; % Length 17, one entry for each interval
quants= quantiz(sig,partition,codebook); % Quantize.
x=quants;
M = 16;
yy = qammod(x,M);
y = awgn(yy,10)
% demodulate
z = qamdemod(y,M);
plot(t,sig, 'cd', t,quants,'bo', t,z,'rx'),grid
legend('Original signal','Quantized signal','recovered signal');
scatterplot(y)
title('scatterplot QAM')

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 3 月 19 日

0 投票

Your line
codebook = [0:1:16]; % Length 22, one entry for each interval
will only assign 17 values, not 22. This is right after your line
partition = [-1:2/15:1]; % Length 21, to represent 22 intervals
which only assigns 16 values...

7 件のコメント

jessica david
jessica david 2011 年 3 月 19 日
Oops! that was a mistake in the comment only. I forgot to change it, what I actually meant was
partition = [-1:2/15:1]; % Length 16, to represent 17 intervals
codebook = [0:1:16]; % Length 16, one entry for each interval
Paulo Silva
Paulo Silva 2011 年 3 月 19 日
codebook length is still 17 not 16
jessica david
jessica david 2011 年 3 月 19 日
i tried codebook = [0:1:15] but it still only gives 15 points only :(
Andrew Newell
Andrew Newell 2011 年 3 月 19 日
>> length([0:16])
ans =
17
jessica david
jessica david 2011 年 3 月 19 日
i tried changing the codebook to [0:1:15], [0:16] etc, but nothing seems to work, i still have only 15 points :(
Paulo Silva
Paulo Silva 2011 年 3 月 19 日
Are you referring to the groups of points in the scatterplot?
jessica david
jessica david 2011 年 3 月 19 日
yes, there has to b 16 points, but i am getting only 15 points

サインインしてコメントする。

タグ

質問済み:

2011 年 3 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by