⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qam_constell_gen.m

📁 国外大学的同志作出来的好程序
💻 M
字号:
function [constell_gray, qpsk_constell_gray, bpsk_constell_gray]=qam_constell_gen(code);
%qam_constell_gen generates M-QAM gray-mapping
%constellation. M<=64;
%
%This function requires communication library.
%If there is no communication library, the saved constellation
%will be retrieved.
a=ver;
comm_version=0;
for ic=1:size(a, 2),
    if (strcmp(a(ic).Name, 'Communications Toolbox')),
        comm_version=str2num(a(ic).Version);
        %disp(['[qam_constell_gen]This matlab has Communication Toolbox, Version:' a(ic).Version '.']);
    end
end
if comm_version<3 | nargin>=1;
    load qam_constell
    return;
end

bpsk_constell_gray=[-1; 1];

M = 64;xybound=10;
x = [0:M-1];
constell = qammod(x,M).';
scatterplot(constell); % Plot the scaled constellation.

% Include text annotations that number the points.
hold on; % Make sure the annotations go in the same figure.
for jj=1:length(constell)
   text(real(constell(jj)),imag(constell(jj)),[' ' num2str(jj)]);
end
axis([-xybound xybound -xybound xybound]);
title('Constellation for 64-QAM in Matlab');
hold off;
print -deps qam64

gray_code = [37 45 46 38 21 29 30 22 ...
    19 27 28 20 35 43 44 36 ...
    23 31 14 52 39 47 12 54 ...
    51 13 42 34 53 11 26 18 ...
    55 63 32 24 7 15 16 8 ...
    5 59 64 56 3 61 48 40 ...
    1 9 60 6 17 25 62 4 ...
    33 41 10 2 49 57 58 50];

constell_gray = constell(gray_code); % Reorder points


M=4; xybound=2;
qpsk_gray_code=[1 2 3 4];
x = [0:M-1];
qpsk_constell = qammod(x,M).';
qpsk_constell_gray=qpsk_constell(qpsk_gray_code);
scatterplot(qpsk_constell); % Plot the scaled constellation.
% Include text annotations that number the points.
hold on; % Make sure the annotations go in the same figure.
for jj=1:length(qpsk_constell)
   text(real(qpsk_constell(jj)),imag(qpsk_constell(jj)),[' ' num2str(jj)]);
end
axis([-xybound xybound -xybound xybound]);
title('Constellation for QPSK in Matlab');
hold off;
print -deps qpsk

save qam_constell constell_gray gray_code constell qpsk_gray_code qpsk_constell_gray bpsk_constell_gray


M=64; xybound=10;
constell_gray2=constell_gray; %*(1/sqrt(21));
% Plot the Gray-coded constellation.
scatterplot(constell_gray2,1,0,'b.'); % Dots for points.
% Include text annotations that number the points in binary.
hold on; % Make sure the annotations go in the same figure.
annot = dec2bin([0:length(constell_gray2)-1],log2(M));
text(real(constell_gray2)-0.55,imag(constell_gray2)-0.35,annot, 'FontSize', 6);
axis([-xybound xybound -xybound xybound]);
line([-xybound xybound], [0 0]);
line([0 0 ], [-xybound xybound]);
title('Constellation for Gray-Coded 64-QAM');
hold off;

print -deps qam64_gray

M=32;xybound=8;
constell_gray2=constell_gray(1:M); %*(1/sqrt(10));
% Plot the Gray-coded constellation.
scatterplot(constell_gray2,1,0,'b.'); % Dots for points.
% Include text annotations that number the points in binary.
hold on; % Make sure the annotations go in the same figure.
annot = dec2bin([0:length(constell_gray2)-1],log2(M));
text(real(constell_gray2)-0.45,imag(constell_gray2)-0.35,annot, 'FontSize', 8);
axis([-xybound xybound -xybound xybound]);
line([-xybound xybound], [0 0]);
line([0 0 ], [-xybound xybound]);
title('Constellation for Gray-Coded 32-QAM');
hold off;

print -deps qam32_gray

M=16;xybound=6;
constell_gray2=constell_gray(1:M); %*(1/sqrt(5));
% Plot the Gray-coded constellation.
scatterplot(constell_gray2,1,0,'b.'); % Dots for points.
% Include text annotations that number the points in binary.
hold on; % Make sure the annotations go in the same figure.
annot = dec2bin([0:length(constell_gray2)-1],log2(M));
text(real(constell_gray2)-0.35,imag(constell_gray2)-0.35,annot);
axis([-xybound xybound -xybound xybound]);
line([-xybound xybound], [0 0]);
line([0 0 ], [-xybound xybound]);
title('Constellation for Gray-Coded 16-QAM');
hold off;

print -deps qam16_gray

M=4;xybound=2;
constell_gray2=qpsk_constell_gray;
% Plot the Gray-coded constellation.
scatterplot(constell_gray2,1,0,'b.'); % Dots for points.
% Include text annotations that number the points in binary.
hold on; % Make sure the annotations go in the same figure.
annot = dec2bin([0:length(constell_gray2)-1],log2(M));
text(real(constell_gray2)-0.05,imag(constell_gray2)-0.15,annot);
axis([-xybound xybound -xybound xybound]);
line([-xybound xybound], [0 0]);
line([0 0 ], [-xybound xybound]);
title('Constellation for Gray-Coded QPSK');
hold off;

print -deps qpsk_gray

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -