📄 dpskmod.m
字号:
function y = dpskmod(x,M,varargin)
% DPSKMOD Differential phase shift keying modulation.
% Y = DPSKMOD(X,M) outputs the complex envelope of the modulation of the
% message signal X using differential phase shift keying modulation. M
% is the alphabet size and must be an integer. The message signal must
% consist of integers between 0 and M-1. For two-dimensional signals, the
% function treats each column as 1 channel.
%
% Y = DPSKMOD(X,M,PHASEROT) specifies the phase rotation (rad) of the
% modulation. In this case, the total per-symbol phase shift is the sum
% of PHASEROT and the phase generated by the differential modulation.
%
% Y = DPSKMOD(X,M,PHASEROT,SYMBOL_ORDER) specifies how the function
% assigns binary words to corresponding integers. If SYMBOL_ORDER
% is set to 'bin' (default), then the function uses a natural binary-coded
% ordering. If SYMBOL_ORDER is set to 'gray', then the function uses
% a Gray-coded ordering.
%
% See also DPSKDEMOD, PSKMOD, PSKDEMOD.
% Copyright 1996-2005 The MathWorks, Inc.
% $Revision: 1.1.6.2 $ $Date: 2004/12/10 19:22:26 $
% error checks
if(nargin<2)
error('comm:dpskmod:numarg','Too few input arguments.');
end
if(nargin>4)
error('comm:dpskmod:numarg','Too many input arguments.');
end
%Check x, phaserot
if ( ~isreal(x) || any(any(ceil(x)~=x)) || ~isnumeric(x) )
error('comm:dpskmod:Xreal','Elements of input X must be integers in the range [0, M-1].');
end
if(~isreal(M) || ~isscalar(M) || M<=0 || (ceil(M)~=M) || ~isnumeric(M) )
error('comm:dpskmod:Mreal','M must be a scalar positive integer.');
end
% check that X are all integers within range.
if (min(min(x)) < 0) || (max(max(x)) > (M-1))
error('comm:dpskmod:Xreal','Elements of input X must be integers in the range [0, M-1].');
end
if(nargin>=3)
Phase_Rotation = varargin{1};
if(isempty(Phase_Rotation))
Phase_Rotation = 0;
elseif(~isreal(Phase_Rotation) || ~isscalar(Phase_Rotation) || ~isnumeric(Phase_Rotation) )
error('comm:dpskmod:phaserotreal','PHASEROT must be a real scalar.');
end
else
Phase_Rotation = 0;
end
% Check SYMBOL_ORDER
if(nargin==2 || nargin==3)
Symbol_Ordering = 'bin'; %default
else
Symbol_Ordering = varargin{2};
if (~ischar(Symbol_Ordering)) || (~strcmpi(Symbol_Ordering,'GRAY')) && (~strcmpi(Symbol_Ordering,'BIN'))
error('comm:dpskmod:SymbolOrder','Invalid symbol set ordering.');
end
end
% --- Assure that X, if one dimensional, has the correct orientation --- %
wid = size(x,1);
if(wid ==1)
x = x(:);
end
% Gray encode if necessary
if (strcmpi(Symbol_Ordering,'GRAY'))
[x_gray,gray_map] = bin2gray(x,'dpsk',M); % Gray encode
[tf,index]=ismember(x,gray_map);
x=index-1;
end
% create a vector for the output.
y = zeros(size(x));
y(1,:) = exp(j*Phase_Rotation + j*2*pi*x(1,:)/M);
for(i=2:size(y,1))
y(i,:) = y(i-1,:) .*exp(j*Phase_Rotation + j*2*pi*x(i,:)/M);
end
% --- restore the output signal to the original orientation --- %
if(wid == 1)
y = y.';
end
% EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -