【问题标题】:Matlab error: Undefined function 'dmod' for input arguments of type 'double'. How come there is no dmod function as it should come with Matlab?Matlab 错误:“double”类型的输入参数的未定义函数“dmod”。为什么没有 dmod 函数,因为它应该与 Matlab 一起使用?
【发布时间】:2013-04-08 00:49:29
【问题描述】:

我一直在做一些考试,需要做一个涉及一些频移键控的练习。这就是我使用 Matlab 中的 dmod 函数的原因——它是 Matlab 自带的。但正如我在控制台中写的那样

yfsk=dmod([1 0], 3, 0.5, 100,'fsk', 2, 1);

它给了我这个

`用于“double”类型的输入参数的未定义函数“dmod”。

我也尝试过doc dmod,它在 matlab 帮助窗口中显示“找不到页面”。

你知道这是因为我没有安装所有的matlab软件包还是matlab 2012a不支持这个功能? 谢谢

【问题讨论】:

  • AFAIK,Matlab 或任何官方工具箱中都没有dmod 函数。
  • @OliCharlesworth:但我的练习纸上说有。我还有什么其他选择?谢谢
  • @OliCharlesworth - 看看这个 matlab 论坛帖子:mathworks.com/matlabcentral/newsreader/view_thread/131786,我猜有 dmod,唯一的问题是 matlab 2012 是否支持它?

标签: matlab


【解决方案1】:

这会很有帮助:

function [y, t] = dmod(x, Fc, Fd, Fs, method, M, opt2, opt3)
%DMOD 
%
%WARNING: This is an obsolete function and may be removed in the future.
%         Please use MODEM.PAMMOD, MODEM.QAMMOD, MODEM.GENQAMMOD, FSKMOD,
%         MODEM.PSKMOD, or MODEM.MSKMOD instead.

%   Y = DMOD(X, Fc, Fd, Fs, METHOD...) modulates the message signal X
%   with carrier frequency Fc (Hz) and symbol frequency Fd (Hz).  The
%   sample frequency of Y is Fs (Hz), where Fs > Fc and where Fs/Fd is
%   a positive integer. For information about METHOD and subsequent
%   parameters, and about using a specific modulation technique,
%   type one of these commands at the MATLAB prompt:
%
%   FOR DETAILS, TYPE     MODULATION TECHNIQUE
%     dmod ask            % M-ary amplitude shift keying modulation
%     dmod psk            % M-ary phase shift keying modulation
%     dmod qask           % M-ary quadrature amplitude shift keying
%                         % modulation
%     dmod fsk            % M-ary frequency shift keying modulation
%     dmod msk            % Minimum shift keying modulation
%   
%   For baseband simulation, use DMODCE.  To plot signal constellations,
%   use MODMAP.
%
%   See also DDEMOD, DMODCE, DDEMODCE, MODMAP, AMOD, ADEMOD.

%   Copyright 1996-2007 The MathWorks, Inc.
%   $Revision: 1.1.6.5 $  $Date: 2007/06/08 15:53:47 $

warnobsolete(mfilename, 'Please use MODEM.PAMMOD, MODEM.QAMMOD, MODEM.GENQAMMOD, FSKMOD, MODEM.PSKMOD, or MODEM.MSKMOD instead.');

swqaskenco = warning('off', 'comm:obsolete:qaskenco');
swapkconst = warning('off', 'comm:obsolete:apkconst');
swmodmap = warning('off', 'comm:obsolete:modmap');
swamod = warning('off', 'comm:obsolete:amod');

opt_pos = 6;        % position of 1st optional parameter

if nargout > 0
   y = []; t = [];
end
if nargin < 1
    feval('help','dmod')
    return;
elseif isstr(x)
    method = lower(deblank(x));
    if length(method) < 3
        error('Invalid method option for DMOD.')
    end
    if nargin == 1
        % help lines for individual modulation method.
        addition = 'See also DDEMOD, DMODCE, DDEMODCE, MODMAP, AMOD, ADEMOD.';
        if method(1:3) == 'qas'
          callhelp('dmod.hlp', method(1:4), addition);
        else
          callhelp('dmod.hlp', method(1:3), addition);
        end
    else
        % plot constellation, make a shift.
        opt_pos = opt_pos - 3;
        M = Fc;
        if nargin >= opt_pos
            opt2 = Fd;
        else
            modmap(method, M);
            return;
        end
        if nargin >= opt_pos+1
            opt3 = Fs;
        else
            modmap(method, M, opt2);
            return;
        end
        modmap(method, M, opt2, opt3);  % plot constellation
    end
    return;
end

if (nargin < 4)
    error('Usage: Y = DMOD(X, Fc, Fd, Fs, METHOD, OPT1, OPT2, OPT3) for passband modulation');
elseif nargin < opt_pos-1
    method = 'samp';
else
    method = lower(method);
end

len_x = length(x);
if length(Fs) > 1
    ini_phase = Fs(2);
    Fs = Fs(1);
else
    ini_phase = 0;      % default initial phase
end

if ~isfinite(Fs) | ~isreal(Fs) | Fs<=0
    error('Fs must be a positive number.');
elseif length(Fd)~=1 | ~isfinite(Fd) | ~isreal(Fd) | Fd<=0
    error('Fd must be a positive number.');
else
    FsDFd = Fs/Fd;      % oversampling rate
    if ceil(FsDFd) ~= FsDFd
        error('Fs/Fd must be a positive integer.');
    end
end
if length(Fc) ~= 1 | ~isfinite(Fc) | ~isreal(Fc) | Fc <= 0
    error('Fc must be a positive number. For baseband modulation, use DMODCE.');
elseif Fs/Fc < 2
    warning('Fs/Fc must be much larger than 2 for accurate simulation.');
end

% determine M
if isempty(findstr(method, '/arb')) & isempty(findstr(method, '/cir'))
    if nargin < opt_pos
        M = max(max(x)) + 1;
        M = 2^(ceil(log(M)/log(2)));
        M = max(2, M);
    elseif length(M) ~= 1 | ~isfinite(M) | ~isreal(M) | M <= 0 | ceil(M) ~= M
        error('Alphabet size M must be a positive integer.');
    end
end

if isempty(x)
    y = [];
    return;
end
[r, c] = size(x);
if r == 1
    x = x(:);
    len_x = c;
else
    len_x = r;
end

% expand x from Fd to Fs.
if isempty(findstr(method, '/nomap'))
    if ~isreal(x) | all(ceil(x)~=x)
        error('Elements of input X must be integers in [0, M-1].');
    end
    yy = [];
    for i = 1 : size(x, 2)
        tmp = x(:, ones(1, FsDFd)*i)';
        yy = [yy tmp(:)];
    end
    x = yy;
    clear yy tmp;
end

if strncmpi(method, 'ask', 3)
    if isempty(findstr(method, '/nomap'))
        % --- Check that the data does not exceed the limits defined by M
        if (min(min(x)) < 0)  | (max(max(x)) > (M-1))
           error('An element in input X is outside the permitted range.');
        end
        y = (x - (M - 1) / 2 ) * 2 / (M - 1);
    else
        y = x;
    end
    [y, t] = amod(y, Fc, [Fs, ini_phase], 'amdsb-sc');
elseif strncmpi(method, 'fsk', 3)
    if nargin < opt_pos + 1
        Tone = Fd;
    else
        Tone = opt2;
    end

    if (min(min(x)) < 0)  | (max(max(x)) > (M-1))
       error('An element in input X is outside the permitted range.');
    end

    [len_y, wid_y] = size(x);
    t = (0:1/Fs:((len_y-1)/Fs))';   % column vector with all the time samples
    t = t(:, ones(1, wid_y));       % replicate time vector for multi-channel operation

    osc_freqs = pi*[-(M-1):2:(M-1)]*Tone;
    osc_output = (0:1/Fs:((len_y-1)/Fs))'*osc_freqs;  

    mod_phase = zeros(size(x))+ini_phase;
    for index = 1:M
        mod_phase = mod_phase + (osc_output(:,index)*ones(1,wid_y)).*(x==index-1);
    end
    y = cos(2*pi*Fc*t+mod_phase);
elseif strncmpi(method, 'psk', 3)
    % PSK is a special case of QASK.
    [len_y, wid_y] = size(x);
    t = (0:1/Fs:((len_y-1)/Fs))';
    if findstr(method, '/nomap')
        y = dmod(x, Fc, Fs, [Fs, ini_phase], 'qask/cir/nomap', M);
    else
        y = dmod(x, Fc, Fs, [Fs, ini_phase], 'qask/cir', M);
    end
elseif strncmpi(method, 'msk', 3)
    M = 2;
    Tone = Fd/2;
    if isempty(findstr(method, '/nomap'))
        % Check that the data is binary
        if (min(min(x)) < 0)  | (max(max(x)) > (1))
           error('An element in input X is outside the permitted range.');
        end
        x = (x-1/2) * Tone;
    end
    [len_y, wid_y] = size(x);
    t = (0:1/Fs:((len_y-1)/Fs))';     % column vector with all the time samples
    t = t(:, ones(1, wid_y));       % replicate time vector for multi-channel operation
    x = 2 * pi * x / Fs;            % scale the input frequency vector by the sampling frequency to find the incremental phase
    x = [0; x(1:end-1)];
    y = cos(2*pi*Fc*t+cumsum(x)+ini_phase);
elseif (strncmpi(method, 'qask', 4) | strncmpi(method, 'qam', 3) |...
         strncmpi(method, 'qsk', 3) )
    if findstr(method,'nomap')
        [y, t] = amod(x, Fc, [Fs, ini_phase], 'qam');
    else
        if findstr(method, '/ar')       % arbitrary constellation
            if nargin < opt_pos + 1
                error('Incorrect format for METHOD=''qask/arbitrary''.');
            end
            I = M;
            Q = opt2;
            M = length(I);
            % leave to the end for processing
            CMPLEX = I + j*Q;
        elseif findstr(method, '/ci')   % circular constellation
            if nargin < opt_pos
                error('Incorrect 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
            CMPLEX = apkconst(NIC, AIC, PIC);
            M = sum(NIC);
        else    % square constellation
            [I, Q] = qaskenco(M);
            CMPLEX = I + j * Q;
        end
        y = [];
        x = x + 1;
        % --- Check that the data does not exceed the limits defined by M
        if (min(min(x)) < 1) | (max(max(x)) > M)
            error('An element in input X is outside the permitted range.');
        end
        for i = 1 : size(x, 2)
            tmp = CMPLEX(x(:, i));
            y = [y tmp(:)];
        end
        ind_y = [1: size(y, 2)]';
        ind_y = [ind_y, ind_y+size(y, 2)]';
        ind_y = ind_y(:);
        y = [real(y) imag(y)];
        y = y(:, ind_y);
        [y, t] = amod(y, Fc, [Fs, ini_phase], 'qam');
    end
elseif strncmpi(method, 'samp', 4)
    % This is for converting an input signal from sampling frequency Fd
    % to sampling frequency Fs.
    [len_y, wid_y] = size(x);
    t = (0:1/Fs:((len_y-1)/Fs))';
    y = x;
else    % invalid method
    error(sprintf(['You have used an invalid method.\n',...
        'The method should be one of the following strings:\n',...
        '\t''ask'' Amplitude shift keying modulation;\n',...
        '\t''psk'' Phase shift keying modulation;\n',...
        '\t''qask'' Quadrature amplitude shift-keying modulation, square constellation;\n',...
        '\t''qask/cir'' Quadrature amplitude shift-keying modulation, circle constellation;\n',...
        '\t''qask/arb'' Quadrature amplitude shift-keying modulation, user defined constellation;\n',...
        '\t''fsk'' Frequency shift keying modulation;\n',...
        '\t''msk'' Minimum shift keying modulation.']));
end

if r==1 & ~isempty(y)
    y = y.';
end

warning(swqaskenco);
warning(swapkconst);
warning(swmodmap);
warning(swamod);

% [EOF]

我相信dmod 函数(通信工具箱)已在最新的 MATLAB 版本中被放弃。

【讨论】:

  • 你说得对,Matlab 2011版删除了。
  • 但在极端需要的情况下,您仍然可以评估使用我发布的功能的想法。
【解决方案2】:

看起来 dmod 已经不复存在了 :-) 这是表明它已被删除的链接:

http://www.mathworks.com/help/comm/release-notes.html?searchHighlight=dmod

应该用 comm.FSKModulator System object 替换它

【讨论】:

    【解决方案3】:

    我想您可能正在寻找信号处理工具箱中的解调功能 (demod)。

    http://www.mathworks.com.au/help/signal/ref/demod.html

    【讨论】:

    • 感谢您的帮助,但如果我更改 do demod 会显示输入参数过多。准确地说,我需要一个 FSK 功能 - 频移键控,方向是调制。之后我会做解调
    • 但我确实找到了类似 comm.FSKModulator System object 的东西
    猜你喜欢
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    • 2014-05-09
    • 1970-01-01
    • 2013-09-01
    相关资源
    最近更新 更多