访问matlab中的函数声明

时间:2017-11-30 06:58:36

标签: matlab convolution

matlab中卷积的

函数是conv()。我的问题是如何才能获得函数本身的实际实现?

2 个答案:

答案 0 :(得分:4)

如果您想了解conv()的工作原理或制作自己版本的转义函数,您可以随时输入

open conv

在命令窗口中。然后你可以看一下原来的功能,并且(如果需要的话)用新的名字保存它并使用你编辑过的版本。

答案 1 :(得分:0)

有两种方法:

  1. 方法1

    当您实施conv()或任何功能(用户定义或in-buit)时,只需右键单击该功能,然后单击打开即可查看功能脚本。

  2. 方法2

    在命令窗口中编写open conv()conv()可以是任何功能

  3. 卷积函数:

    function c = conv(a, b, shape)
    %CONV Convolution and polynomial multiplication.
    %   C = CONV(A, B) convolves vectors A and B.  The resulting vector is
    %   length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]). If A and B are
    %   vectors of polynomial coefficients, convolving them is equivalent to
    %   multiplying the two polynomials.
    %
    %   C = CONV(A, B, SHAPE) returns a subsection of the convolution with size
    %   specified by SHAPE:
    %     'full'  - (default) returns the full convolution,
    %     'same'  - returns the central part of the convolution
    %               that is the same size as A.
    %     'valid' - returns only those parts of the convolution 
    %               that are computed without the zero-padded edges. 
    %               LENGTH(C)is MAX(LENGTH(A)-MAX(0,LENGTH(B)-1),0).
    %
    %   Class support for inputs A,B: 
    %      float: double, single
    %
    %   See also DECONV, CONV2, CONVN, FILTER, XCORR, CONVMTX.
    %
    %   Note: XCORR and CONVMTX are in the Signal Processing Toolbox.
    
    
    %   Copyright 1984-2013 The MathWorks, Inc.
    
    if ~isvector(a) || ~isvector(b)
      error(message('MATLAB:conv:AorBNotVector'));
    end
    
    if nargin < 3
        shape = 'full';
    end
    
    if ~ischar(shape) && ~(isstring(shape) && isscalar(shape))
      error(message('MATLAB:conv:unknownShapeParameter'));
        end
        if isstring(shape)
            shape = char(shape);
        end
    
        % compute as if both inputs are column vectors
        c = conv2(a(:),b(:),shape);
    
        % restore orientation
        if shape(1) == 'f' || shape(1) == 'F'  %  shape 'full'
            if length(a) > length(b)
                if size(a,1) == 1 %row vector
                    c = c.';
                end
            else
                if size(b,1) == 1 %row vector
                    c = c.';
                end
            end
        else
            if size(a,1) == 1 %row vector
                c = c.';
            end
        end
    end
    if isstring(shape)
        shape = char(shape);
    end
    
    % compute as if both inputs are column vectors
    c = conv2(a(:),b(:),shape);
    
    % restore orientation
    if shape(1) == 'f' || shape(1) == 'F'  %  shape 'full'
        if length(a) > length(b)
            if size(a,1) == 1 %row vector
                c = c.';
            end
        else
            if size(b,1) == 1 %row vector
                c = c.';
            end
        end
    else
        if size(a,1) == 1 %row vector
            c = c.';
        end
    end
    

    更新:

    这与问题无关。无论如何,你想要计算卷积积分,但matlab中的conv()函数定义是:

    w = conv(u,v)返回向量 u和v的卷积。如果u和v是多项式系数的向量,则对它们进行卷积相当于将两个多项式相乘。

    请注意,这是离散卷积,并没有为您提供结果的公式。如果您需要结果公式,请使用符号工具箱计算http://localhost:81/something

    请参阅此Convolution Integral