📄 dmodce.m
字号:
function y = dmodce(x, Fd, Fs, method, M, opt2, opt3)
%DMODCE Complex envelope of digital modulation.
% Y = DMODCE(X, Fd, Fs, METHOD, OPT1, OPT2, OPT3) output Y, the complex
% envelope of a digital modulated signal. The sampling frequency for X
% is Fd (Hz). The sampling frequency for Y is Fs (Hz). Fs must be larger
% than Fd. Fs/Fc must be a positive integer. The time interval between
% two successive points in X is 1/Fd. The column number of the modulated
% signal Y is Fs/Fd times the length of the input signal X. The time
% interval between two successive points in Y is 1/Fs. When Fs is a two
% element vector, the second element specifies the initial phase (rad)
% in the modulation.
%
% METHOD is a string, which can be one of the following:
% 'ask' M-ary Amplitude shift keying modulation.
% 'psk' M-ary Phase shift keying modulation.
% 'qask' M-ary Quadrature amplitude shift-keying modulation.
% 'fsk' M-ary Frequency shift keying modulation.
% 'msk' Minimum shift keying modulation.
% 'sample' Up sample the input signal.
%
% With a switch '/nomap' appended to the string of METHOD variable, the
% function will not process the digital to analog mapping part. The
% input signal is assumed to have sampling frequency Fs.
%
% DMODCE(METHOD, OPT1, OPT2, OPT3) plots constellation layout.
%
% Use DMODCE(METHOD) to view the help for a specific method.
%
% See also DDEMODCE, MODMAP. DEMODMAP, COMMOD, COMDEMOD.
%
% Wes Wang 1/9/95, 10/5/95
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 17:56:52 $
%position for optional parameters.
opt_pos = 5;
plot_const = 0;
if nargin < 1
feval('help','dmodce')
return;
elseif isstr(x)
method = lower(deblank(x));
if length(method) < 3
error('Invalid method option for dmodce.')
end
if nargin == 1
% help lines for individual modulation method.
addition = 'See also DDEMODCE, DMOD, DDEMOD, MODMAP, DEMODMAP, AMOD, ADEMOD.';
if method(1:3) == 'qas'
callhelp('dmodce.hlp',method(1:4),addition);
else
callhelp('dmodce.hlp',method(1:3),addition);
end
return;
else
plot_const = 1;
opt_pos = opt_pos - 3;
M = Fd;
if nargin > opt_pos
opt2 = Fs;
end;
if nargin > opt_pos+1
opt3 = method;
end;
end;
else
len_x = length(x);
if length(Fs) > 1
ini_phase = Fs(2);
Fs = Fs(1);
else
ini_phase = 0;
end;
if length(Fd) > 1
offset = Fd(2);
Fd = Fd(1);
else
offset = 0;
end;
if (Fs == 0) | (Fd == 0) | isempty(Fd) | isempty(Fs)
FsDFd = 1;
else
FsDFd = Fs / Fd;
if (ceil(FsDFd) ~= FsDFd) | (FsDFd <= 0)
error('Fs / Fd must be a positive integer.')
end;
[r, c] = size(x);
if r * c == 0
y = [];
return;
end;
if r == 1
x = x(:);
len_x = c;
else
len_x = r;
end;
if isempty(findstr(method, '/nomap'))
yy = [];
for i = 1 : size(x, 2)
tmp = x(:, ones(1, FsDFd)*i)';
yy = [yy tmp(:)];
end;
x = yy;
clear yy tmp
end;
end;
end;
offset = rem(offset, FsDFd);
if offset < 0
offset = rem(offset + FsDFd, FsDFd);
end;
if (nargin < 3) & ~isstr(x)
disp('Usage: Y=DMODCE(X, Fd, Fs, METHOD, OPT1, OPT2, OPT3) for modulation mapping');
return;
elseif nargin < opt_pos-1
method = 'samp';
end;
% determine M
if nargin < opt_pos
% this will happen only
M = max(max(x)) + 1;
M = 2^(ceil(log(M)/log(2)));
M = max(2, M);
end;
method = lower(method);
if length(method) < 3
method = [method ' '];
end;
if strcmp(method(1:3), 'ask')
if plot_const
plot([0 0], [-1.1 1.1], 'w-', [-1.1, 1.1], [0 0], 'w-', ([0:M-1] - (M - 1) / 2 ) * 2 / (M - 1), zeros(1, M), '*');
axis([-1.1 1.1 -1.1 1.1])
xlabel('In-phase component');
title('ASK constellation')
else
if isempty(findstr(method, '/nomap'))
y = (x - (M - 1) / 2 ) * 2 / (M - 1);
else
y = x;
end;
if ini_phase
y = y * exp(j * ini_phase);
end;
end;
elseif findstr(method, 'fsk')
if nargin < opt_pos + 1
Tone = 2 * Fd / M;
else
Tone = opt2;
end;
if plot_const
x = [0 : M-1] * Tone;
x = x([1 1 1], :);
x = x(:)';
tmp = [0 1 0];
tmp = tmp(ones(1, M), :)';
tmp = tmp(:)';
tmp(2) = 2;
plot(x, tmp);
xlabel('Baseband spectrum for FSK (Hz)')
title('FSK constellation')
else
if isempty(findstr(method, '/nomap'))
x = x * Tone;
end;
y = x;
[len_y, wid_y] = size(y);
for i = 1 : ceil(len_y/FsDFd)
y((i-1)*FsDFd+1 : min(i*FsDFd, len_y), :) = ...
exp(j * 2 * pi / Fs * cumsum([zeros(1, wid_y); y((i-1)*FsDFd+1 : min(i*FsDFd, len_y)-1, :)]) ...
+ j*ini_phase);
% exp(j * 2 * pi / Fs * cumsum(y((i-1)*FsDFd+1 : min(i*FsDFd, len_y), :)) ...
end;
end;
elseif findstr(method, 'psk')
if plot_const
apkconst(M);
else
if isempty(findstr(method, '/nomap'))
method = 'qask/cir';
else
method = 'qask/cir/nomap';
end;
y = dmodce(x, Fs, [Fs, ini_phase], method, M, 1, 0);
end;
elseif strcmp(method, 'msk')
%This is a special case of fsk call back to get fsk
if plot_const
Fd = M;
x = [0 0 0 Fd Fd Fd];
tmp = [0 2 0 0 1 0];
plot(x, tmp);
xlabel('Baseband spectrum for FSK')
title('FSK constellation')
else
M = 2;
Tone = Fd;
if isempty(findstr(method, '/nomap'))
y = x * Tone;
else
y = x;
end;
len_y = size(y, 1);
method(1) = 'f';
for i = 1 : ceil(len_y/FsDFd)
y((i-1)*FsDFd+1 : min(i*FsDFd, len_y), :) = ...
exp(j * 2 * pi / Fs * cumsum(y((i-1)*FsDFd+1 : min(i*FsDFd, len_y), :)) ...
+ j*ini_phase);
end;
end;
elseif ~isempty(findstr(method, 'qas')) |...
~isempty(findstr(method, 'qam')) |...
~isempty(findstr(method, 'qsk'))
if findstr(method, '/nomap')
y = amodce(x, [Fs, ini_phase], 'qam');
else
if findstr(method, '/ar')
% arbitraryly defined I, Q.
if nargin < opt_pos + 1
error('In correct format for METHOD=''qask/arbitrary''.');
end;
I = M;
Q = opt2;
M = length(I);
if plot_const
axx = max(max(abs(I))) * [-1 1] + [-.1 .1];
axy = max(max(abs(Q))) * [-1 1] + [-.1 .1];
plot(I, Q, 'r*', axx, [0 0], 'w-', [0 0], axy, 'w-');
axis('equal')
axis('off');
text(axx(1) + (axx(2) - axx(1))/4, axy(1) - (axy(2) - axy(1))/30, 'QASK Constellation');
return;
else
% leave to the end for processing
CMPLEX = I + j*Q;
end;
elseif findstr(method, '/ci')
% circle defined NIC, AIC, PIC.
if nargin < opt_pos
error('In correct format for METHOD=''qask/circle''.');
end;
NIC = M;
M = length(NIC);
if nargin < opt_pos+1
AIC = [1 : M];
else
AIC = opt2;
end;
if nargin < opt_pos + 2
PIC = NIC * 0;
else
PIC = opt3;
end;
if plot_const
apkconst(NIC, AIC, PIC);
return;
else
CMPLEX = apkconst(NIC, AIC, PIC);
M = sum(NIC);
end;
else
%consider as square style.
if plot_const
qaskenco(M);
return;
else
[I, Q] = qaskenco(M);
CMPLEX = I + j * Q;
end;
end;
y = [];
x = x + 1;
if (min(min(x)) < 1) | (max(max(x)) > M)
error('Element in input X exceeded range.');
end;
if max(max(x)) > length(CMPLEX)
error(['Maximum element in x exceeds limit M = ' num2str(length(CMPLEX))])
elseif min(min(x)) < 1
error('Element in input X cannot be a negative number.')
end;
for i = 1 : size(x, 2)
tmp = CMPLEX(x(:, i));
y = [y tmp(:)];
end;
if ini_phase
y = y * exp(j * ini_phase);
end;
end;
elseif findstr(method, 'sam')
%This is made possible to convert an input signal from sampling frequency Fd
%to sampling frequency Fs.
y = x;
else
%The choice is not a valid one.
disp('You have used an invalid method. The method should be one of the following string:')
disp(' ''ask'' Amplitude shift keying modulation;')
disp(' ''psk'' Phase shift keying modulation;')
disp(' ''qask'' Quadrature amplitude shift-keying modulation, square constellation;')
disp(' ''qask/cir'' Quadrature amplitude shift-keying modulation, circle constellation;')
disp(' ''qask/arb'' Quadrature amplitude shift-keying modulation, user defined constellation;')
disp(' ''fsk'' Frequency shift keying modulation;')
disp(' ''msk'' Minimum shift keying modulation;')
disp(' ''sample'' Convert sample frequency Fd input to sample frequency Fs output.')
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -