www.pudn.com > MATLAB(Proakis).rar > MODMAP.M, change:2005-12-13,size:8313b

```function y = modmap(x, Fd, Fs, method, M, opt2, opt3)
%MODMAP Maps digital signal to analog signal for modulation.
%       Y = MODMAP(X, Fd, Fs, METHOD, OPT1, OPT2, OPT3) maps a sample
%       frequency Fd (Hz) signal vector X in to a sample frequency Fs (Hz)
%       in-phase and quadrature components in Y. Y is a two column matrix.
%       The first column is an in-phase component and second column is a
%       quadrature component. When METHOD = 'ask', Y is a column vector
%       instead of a matrix. This function does mapping only. For digital
%       modulation, use DMOD for passband simulation and DMODCE for baseband
%       simulation.
%
%       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.
%       'fsk'       M-ary Frequency shift keying modulation.
%       'msk'       Minimum shift keying modulation.
%       'sample'    Up sample the input signal.
%
%       MODMAP(METHOD, OPT1, OPT2, OPT3) plots the constellation of given
%       method.
%
%       Use MODMAP(METHOD) to view the help for a specific method.
%

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

%position for optional parameters.
opt_pos = 5;
plot_const = 0;
if nargin < 1
feval('help','modmap')
return;
elseif isstr(x)
if exist('method')
tmp_sto = method;
end;
method = lower(deblank(x));
if findstr(method, 'samp')
method = 'samp';
end;
if nargin == 1
% help lines for individual modulation method.
if strcmp(method, '')
end;
hand = fopen('modmap.hlp');
if hand<=0
error('The Communications Toolbox on your machine is not a completed one.')
else
x = fscanf(hand, '%c', Inf);
index_begin = findstr(x, [method,'_help_begin']);
index_end = findstr(x, [method,'_help_end']);
if index_end > index_begin
x = x(index_begin+13+length(method):index_end-1);
fprintf('%s', x);
disp(' ')
else
disp(['No help for ', method]);
end;
end;
fclose(hand);
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 = tmp_sto;
end;
end;
else
len_x = length(x);
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;
yy = [];
for i = 1 : size(x, 2)
tmp = x(:, ones(1, FsDFd)*i)';
yy = [yy tmp(:)];
end;
x = yy;
clear yy tmp
end;
end;

if ~isstr(x)
if nargin < 3
disp('Usage: Y=MODMAP(X, Fd, Fs, METHOD, OPT1, OPT2, OPT3) for modulation mapping');
return;
elseif nargin < opt_pos-1
method = 'sample';
end;
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 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');
else
y = (x - (M - 1) / 2 ) * 2 / (M - 1);
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
y = x * Tone;
end;
elseif findstr(method, 'psk')
if plot_const
apkconst(M);
else
y = modmap(x, Fs, Fs, 'qask/cir', M);
end;
elseif findstr(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;
y = x * Tone;
end;
~isempty(findstr(method, 'qam')) |...
~isempty(findstr(method, 'qsk'))
if findstr(method, '/ar')
% arbitraryly defined I, Q.
if nargin < opt_pos + 1
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
end;
elseif findstr(method, '/ci')
% circle defined NIC, AIC, PIC.
if nargin < opt_pos
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
inx = apkconst(NIC, AIC, PIC);
I = real(inx);
Q = imag(inx);
M = sum(NIC);
end;
else
%consider as square style.
if plot_const
return;
else
end;
end;
y = [];
x = x + 1;
if (min(min(x)) < 1)  | (max(max(x)) > M)
error('Element in input X exceeded range.');
end;
for i = 1 : size(x, 2)
tmp = I(x(:, i));
y = [y tmp(:)];
tmp = Q(x(:, i));
y = [y tmp(:)];
end;
elseif findstr(method, 'samp')
%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;')