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

📄 qaskenco.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [x,y]=qaskenco(msg,M)
%QASKENCO Calculates a QASK square constellation mapping.
%       QASKENCO(M) plots a QASK square constellation with M-ary number M.
%       M must be a power of 2.
%
%       QASKENCO(MSG, M) plots the location of MSG in constellation with
%       M-ary number M. The elements in MSG must be integers in range
%       [0, M-1].
%
%       [X, Y] = QASKENCO(M) outputs the in-phase component and quadrature 
%       component of the QASK square constellation into variable X and Y
%       respectively.
%
%       [X, Y] = QASKENCO(MSG, M) encodes the message signal given in MSG
%       into in-phase and quadrature vectors X and Y.
%   
%       The output maximum number are listed as follows:
%          M = 2,   maximum = 1;   M = 4,   maximum = 1;
%          M = 8,   maximum = 3;   M = 16,  maximum = 3;
%          M = 32,  maximum = 5;   M = 64,  maximum = 7;
%          M = 128, maximum = 11;  M = 256, maximum = 15;
%
%       See also QASKDECO.

%       Wes Wang 10/11/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 18:01:50 $

if nargin < 1
    disp('Usage: QASKENCO(M)');
end;

if nargin == 1
    M = msg;
end;

if M < 0
    error('M must be a positive number')
elseif M > 256
    error('M must be less or equal to 256 for sqaure qask constellation.')
end;

K = log(M) ./ log(2);
if M ~= 2^K
    error('M must equal to 2^K where K is an integer.')
end;

if nargin == 1
    msg = 0:M-1;
end;

% define a table for the coding. The decoding could be a 
% two dimentional trace-back.
A=11;C=13;E=15;
tabx = [1  1 -1 -1,...    %M = 4
        3  3 -3 -3,...    %M = 8
        1  1 -1 -1 3  3 -3 -3,...    %M = 16
        1  1 -1 -1 3  3 -3 -3 5  5 -5 -5 5  5 -5 -5,...    %M = 32
        5  5 -5 -5 5  5 -5 -5 7  7 -7 -7 7  7 -7 -7,...
        1  1 -1 -1 3  3 -3 -3 7  7 -7 -7 7  7 -7 -7,...    %M = 64
        9  9 -9 -9 9  9 -9 -9 9  9 -9 -9 9  9 -9 -9,...
        A  A -A -A A  A -A -A A  A -A -A A  A -A -A,...
        1  1 -1 -1 3  3 -3 -3 5  5 -5 -5 7  7 -7 -7,...
        1  1 -1 -1 3  3 -3 -3 5  5 -5 -5 7  7 -7 -7,...    %M = 128
        9  9 -9 -9 9  9 -9 -9 A  A -A -A A  A -A -A,...
        1  1 -1 -1 3  3 -3 -3 5  5 -5 -5 7  7 -7 -7,...   
        9  9 -9 -9 A  A -A -A C  C -C -C E  E -E -E,...
        1  1 -1 -1 3  3 -3 -3 5  5 -5 -5 7  7 -7 -7,...   
        9  9 -9 -9 A  A -A -A C  C -C -C E  E -E -E,...
        C  C -C -C E  E -E -E C  C -C -C E  E -E -E,...
        C  C -C -C E  E -E -E C  C -C -C E  E -E -E,...
        C  C -C -C E  E -E -E C  C -C -C E  E -E -E,...
];
taby = [1 -1  1 -1,...    %M = 4
        1 -1  1 -1,...    %M = 8
        3 -3  3 -3 3 -3  3 -3,...    %M = 16
        5 -5  5 -5 5 -5  5 -5 1 -1  1 -1 3 -3  3 -3,...    %M = 32
        5 -5  5 -5 7 -7  7 -7 5 -5  5 -5 7 -7  7 -7,...
        7 -7  7 -7 7 -7  7 -7 1 -1  1 -1 3 -3  3 -3,...    %M = 64
        1 -1  1 -1 3 -3  3 -3 5 -5  5 -5 7 -7  7 -7,...
        1 -1  1 -1 3 -3  3 -3 5 -5  5 -5 7 -7  7 -7,...
        9 -9  9 -9 9 -9  9 -9 9 -9  9 -9 9 -9  9 -9,...
        A -A  A -A A -A  A -A A -A  A -A A -A  A -A,...    %M = 128
        9 -9  9 -9 A -A  A -A 9 -9  9 -9 A -A  A -A,...
        C -C  C -C C -C  C -C C -C  C -C C -C  C -C,...
        C -C  C -C C -C  C -C C -C  C -C C -C  C -C,...
        E -E  E -E E -E  E -E E -E  E -E E -E  E -E,...
        E -E  E -E E -E  E -E E -E  E -E E -E  E -E,...
        1 -1  1 -1 1 -1  1 -1 3 -3  3 -3 3 -3  3 -3,...
        5 -5  5 -5 5 -5  5 -5 7 -7  7 -7 7 -7  7 -7,...
        9 -9  9 -9 9 -9  9 -9 A -A  A -A A -A  A -A,...    %M =256
];
msg = msg + 1;
if nargout > 0
    x = tabx(msg);
    y = taby(msg);
else
    axx =  max(max([tabx(msg) taby(msg)])) * [-1 1] + [-.5 .5];
%    handle = plot(tabx(msg), taby(msg), 'yx', axx, [0 0], 'w-', [0 0], axx, 'w-');
    handle = plot(tabx(msg), taby(msg), 'm.');
    set(handle,'Markersize',10);
    set(get(handle(1),'parent'),'box','off', 'Xlim',axx, 'Ylim',axx, 'defaulttextfontsize', 9)
    for i = 1 : length(msg)
        text(tabx(msg(i)), taby(msg(i)), num2str(msg(i)-1));
    end;
    axis('equal');
%    xlabel('In-phase');
%    ylabel('Quadrature');
    title('QASK Constallation');
%    text(axx(1) + (axx(2)-axx(1))/5, axx(1)-(axx(2)-axx(1))/20, 'QASK Constellation');
%    axis('off')
end;

%---end of QASKENCO.M--

⌨️ 快捷键说明

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