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

📄 amodce.m

📁 数字通信第四版原书的例程
💻 M
字号:
function y = amodce(x, Fs, method, opt1, opt2, opt3)
%AMODCE Complex envelope of analog modulation.
%       Y = AMODCE(X, Fs, METHOD, OPT1, OPT2, OPT3) outputs complex envelope of
%       the modulation of the input signal X. The input and the output have
%       the same sample frequency Fs (Hz). When Fs is a two element vector,
%       the second element is the initial phase (rad) of the carrier signal in
%       the modulation. The modulation method is specified in the input
%       variable METHOD. Input variables OPT1, OPT2, and OPT3 are optional
%       variables based on METHOD in use. 
%
%       METHOD is a string, which can be one of the following:
%       'am' or 'amdsb-tc'  Amplitude demodulation, double sideband with
%                   transmission carrier
%       'amdsb-sc'  Amplitude demodulation, double sideband suppressed carrier
%       'amssb'     Amplitude demodulation, single sideband suppressed carrier
%       'qam'       Quadrature amplitude demodulation
%       'fm'        Frequency demodulation
%       'pm'        Phase demodulation
%
%       Use AMODCE(METHOD) to view the help for a specific method.
%
%       See also: ADEMODCE.

%       Wes Wang 11/9/94, 9/30/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:51:46 $
%       This function calls amodce.hlp for help

opt_pos = 4;
if isstr(x)
    method = deblank(x);
    if strcmp(method, 'am')
        method = 'amdsb-tc';
    end;
    addition = 'See also: ADEMODCE, DMOD, DDEMOD, AMOD, ADEMOD.';
    callhelp('amodce.hlp',method, addition);
    return;
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 nargin < 1
    feval('help', 'amodce');
    return;
elseif nargin < 2
    Fs = 1;
    method = 'am';
elseif nargin < 3
    method = 'am'
end;
method = lower(method);

if length(Fs) >= 2
    ini_phase = Fs(2);
    Fs = Fs(1);
else
    ini_phase = 0;
    if length(Fs) < 1
        Fs = 1;
    end
end
samp_time = 1/Fs;

%begin of the calculation.
if strcmp(method, 'amdsb-sc')
    y = x * exp(j*ini_phase);
elseif strcmp(method, 'amdsb-tc') | strcmp(method, 'am')
    if nargin < 4
        opt1 = min(min(x));
    end;
    y = (x + opt1) * exp(j*ini_phase);
elseif findstr(method, 'amssb')
    % need to use Hilbert transform filter.
    if isempty(findstr(method, '/time'))
        % do the Hilbert transform in frequence domain.
        y = x;
        for i = 1 : size(x, 2)
            y(:, i) = (x(:, i) + j*imag(hilbert(x(:, i))))*exp(j*ini_phase);
        end;
    else
        % do the Hilber transform in time domain.
        if nargin < opt_pos
            [num,den] = hilbiir(1/Fs);
        elseif nargin == opt_pos
            error(' Need to specify both numerator and denominator.')
        else
            num = opt1;
            den = opt2;
        end;
        y = x;
        for i = 1 : size(x, 2)
            y(:, i) = filter(num, den, x(:, i));
            y(:, i) = (x(:, i) + j * y(:, i)) * exp(j * ini_phase);
        end;
    end;
elseif strcmp(method, 'qam')
    y = [];
    wid_x = size(x, 2);
    if ceil(wid_x/2) ~= wid_x/2
        error(' The column number for the input X must be a even number.');
    end;
    for i = 1 : 2 : wid_x
        y = [y (x(:,2*i-1) + j*x(:,2*i))*exp(j * ini_phase)];
    end;
elseif strcmp(method, 'fm')
    x = 2 * pi / Fs * x;
%   question here, should add an zero or not.
    x = [zeros(1, size(x, 2)); cumsum(x(1:size(x, 1)-1, :))];
%    x = cumsum(x);
    y = exp(j*(x+ini_phase));
elseif strcmp(method, 'pm')
    y = exp(j*(x+ini_phase));
elseif strcmp(method, 'ask')
    if nargin < 4
        opt1 = max(max(x)) + 1;
        opt1 = 2^(ceil(log(opt1)/log(2)));
    end;
    if nargin < 5
        opt2 = 1;
    end;
    x = (x - (opt1-1)/2)*2*opt2/(opt1 - 1)
    y = x*exp(j*ini_phase);
elseif strcmp(method, 'psk')
    if nargin < 4
        opt1 = max(max(x)) + 1;
        opt1 = 2^(ceil(log(opt1)/log(2)));
    end;
    x = 2 * pi * x / opt1;
    y = exp(j * (x + ini_phase));
elseif strcmp(method, 'qask')
    if nargin < 4
        opt1 = max(max(x)) + 1;
        opt1 = 2^(ceil(log(opt1)/log(2)));
    end;
     [s1,s2] = qaskenco([1:opt1], opt1);
    if min(min(x)) < 0
        error('The input signal for MODULPE has illegal element.');
    elseif max(max(x)) > opt1-1
        error('The input signal for MODULPE has element larger than given limit.');
    end;
    x = x + 1;
    y = (s1(x) + j * s2(x)) * exp(j*ini_phase);
elseif strcmp(method, 'apk')
    if nargin < 6
        error('Not enough input parameters.');
    end;
    z = sigsetpl(opt1, opt2, op3);
    y = z(x+1) * exp(j * ini_phase);
elseif strcmp(method, 'fsk')
    % check the parameters
    if nargin < 4
        opt1 = max(max(x)) + 1;
        opt1 = 2^(ceil(log(opt1)/log(2))); 
    end;
    if nargin < 5
        opt2 = 2;
    end;
    if nargin < 6
        opt3 = 1/opt1;
    end;
    % modulation.
    x = x(:)';
    len_x = length(x);
    y = cumsum([0, x(1:opt2:len_x-opt2)]);
    y = y(ones(1, opt2), :);
    y = ([1/opt2:1/opt2:1]'*x(1:opt2:len_x) + y) * pi * opt3;
    y = y(:);
    y = exp(j*(ini_phase+y));
elseif strcmp(method, 'msk')
    if nargin < 4
        opt1 = 2;
    end;
    % it is a special case of fsk.
    y = amodce(x, 'fsk', ini_phase, 2, opt1, 1/2);
else
    disp(['Modualtion method ', method, ' is not a legal option in function AMODCE.'])
    disp('The current available mehtods are:');
    disp('  amdsb-tc Amplitude modulation, double sideband with transmission carrier.')
    disp('  amdsb-sc Amplitude modulation, double sideband supressed carrier.')
    disp('  amssb Amplitude modulation, single side band supressed carrier.')
    disp('  qam Quadrature Amplitude modulation.')
    disp('  pm Phase modulation.')
    disp('  ask Amplitude shift keying modulation.')
    disp('  psk Phase shift keying modulation.')
    disp('  qask Quadrature amplitude shift-keying modulation.')
    disp('  apk Amplitude shift keying/phase shift keying modulation.')
    disp('  fsk Frequency shift keying modulation.')
    disp('  msk Minimum shift keying modulation.')
end;

⌨️ 快捷键说明

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