功能:是二维卷积运算函数(与convmtx2相似)。如果a和b是两个离散变量n1和n2的函数,则关于a和b的二维卷积运算数学公式如下:

用法:C = conv2(A,B)
C = conv2(hcol,hrow,A)
C = conv2(...,'shape')
C = conv2(A,B)计算数组A和B的卷积。如果一个数组描述了一个二维FIR滤波器,则另一个数组被二维滤波。当A的大小为[ma,na],B的大小为[mb,nb]时,C的大小为[ma+mb-1,mb+nb-1]。‘shape’见下表
参数值
含义
‘full’
默认值,返回全部二维卷积值。
‘same’
返回与A大小相同卷积值的中间部分
‘valid’
当all(size(A)>=size(B)),C的大小为[ma+mb-1,mb+nb-1];否则,C返回[]。在n维卷积运算中,C的大小为max(size(A)- size(B)+1,0)

例子:


s = [1 2 1; 0 0 0; -1 -2 -1];


A = zeros(10);


A(3:7,3:7) = ones(5);


H = conv2(A,s);


mesh(H)



Matlab的帮助:

conv2

2-D convolution

Syntax

C = conv2(A,B)
C = conv2(hcol,hrow,A)
C = conv2(...,'shape')

Description

C = conv2(A,B) computes the two-dimensional convolution of matrices A and B. If one of these matrices describes a two-dimensional finite impulse response (FIR) filter, the other matrix is filtered in two dimensions.

The size of C in each dimension is equal to the sum of the corresponding dimensions of the input matrices, minus one. That is, if the size of A is [ma,na] and the size of B is [mb,nb], then the size of C is [ma+mb-1,na+nb-1].

The indices of the center element of B are defined as floor(([mb nb]+1)/2).

C = conv2(hcol,hrow,A) convolves A first with the vector hcol along the rows and then with the vector hrow along the columns. If hcol is a column vector and hrow is a row vector, this case is the same as C = conv2(hcol*hrow,A).

C = conv2(...,'shape') returns a subsection of the two-dimensional convolution, as specified by the shape parameter:

full

Returns the full two-dimensional convolution (default).

same

Returns the central part of the convolution of the same size as A.

valid

Returns only those parts of the convolution that are computed without the zero-padded edges. Using this option, C has size [ma-mb+1,na-nb+1] when all(size(A) >= size(B)). Otherwise conv2 returns [].

Note   If any of A, B, hcol, and hrow are empty, then C is an empty matrix [].

Algorithm

conv2 uses a straightforward formal implementation of the two-dimensional convolution equation in spatial form. If and are functions of two discrete variables, and , then the formula for the two-dimensional convolution of and is

In practice however, conv2 computes the convolution for finite intervals.

Note that matrix indices in MATLAB always start at 1 rather than 0. Therefore, matrix elements A(1,1), B(1,1), and C(1,1) correspond to mathematical quantities a (0,0), b (0,0), and c (0,0).

Examples

Example 1

For the 'same' case, conv2 returns the central part of the convolution. If there are an odd number of rows or columns, the "center" leaves one more at the beginning than the end.

This example first computes the convolution of A using the default ('full') shape, then computes the convolution using the 'same' shape. Note that the array returned using 'same' corresponds to the underlined elements of the array returned using the default shape.

A = rand(3);
B = rand(4);
C = conv2(A,B); % C is 6-by-6
C =     0.1838  0.2374  0.9727  1.2644  0.7890  0.3750     0.6929  1.2019  1.5499  2.1733  1.3325  0.3096     0.5627  1.5150    1.0602     0.9986  2.3811    0.8462     0.3089  1.1419    0.6841     0.3287  0.9347  1.6464  1.7928  1.2422  0.5423    Cs = conv2(A,B,'same')   % Cs is the same size as A: 3-by-3  Cs =     2.3576  3.1553  2.5373     3.4302  3.5128  2.4489     1.8229  2.1561  1.6364


Matlab 卷积函数 ——conv2相关推荐

  1. matlab中conv什么意思,matlab卷积函数conv matlab中conv()是什么意思?

    matlab中conv()是什么意思? conv(向量卷积运算) 两个向量卷积,简单理解其实就是多项式乘法. 比如:p=[1 2 3],q=[1 1]是两个向量,p和q的卷积计算方法如下: 把p的元素 ...

  2. Matlab卷积函数之conv、deconv、conv2、convn

    目录 1.conv:卷积和多项式乘法 2.deconv2:去卷积和多项式除法 3.conv2:二维卷积 4.convn:N维卷积 1.conv:卷积和多项式乘法 matlab官网解释: 示例:求多项式 ...

  3. 数字信号处理matlab卷积函数conv,filter函数详细介绍三秒钟就看懂。

    %x (n) =sin( pi*n/ 5),-10<= 10 (正弦离散函数) n1=-10:1:10; x1=sin(pi*n1/5); subplot(2,2,1); stem(n1,x1, ...

  4. Matlab中矩阵卷积函数convn

    Matlab中矩阵卷积函数convn 最近在看CNN做手写数字识别,其中CNN中Convolution在图像处理中就涉及了矩阵卷积.因为博主有了奥本海姆<信号与系统>中一维卷积的基础,这里 ...

  5. matlab conv实现,MATLAB卷积运算(conv)以及通用的卷积函数my_conv的实现

    conv(向量卷积运算) 两个向量卷积,简单理解其实就是多项式乘法. 比如:p=[1 2 3],q=[1 1]是两个向量,p和q的卷积计算方法如下: 把p的元素作为一个多项式的系数,多项式按升幂(或降 ...

  6. 【数字信号处理】卷积编程实现 ( Matlab 卷积和多项式乘法 conv 函数 | 使用 matlab 代码求卷积并绘图 )

    文章目录 一.Matlab 卷积和多项式乘法 conv 函数 二.使用 matlab 代码求卷积并绘图 一.Matlab 卷积和多项式乘法 conv 函数 Matlab 文档地址 : https:// ...

  7. 【学习笔记】Matlab自编图像卷积函数

    图像卷积原理 代码 %卷积函数 %made by yao function result = myconv(kernel,img)[k,num] = size(kernel);%判断传入的数组是否为双 ...

  8. matlab doc函数,matlab常用函数.doc

    matlab常用函数.doc MatLab 常用函数 1. 特殊变量与常数 ans 计算结果的变量名 computer 确定运行的计算机 eps 浮点相对精度 Inf 无穷大 I 虚数单位 name ...

  9. Matlab参考函数

    附录1 常用命令 附录1.1 管理用命令 函数名 功能描述 函数名 功能描述 addpath 增加一条搜索路径 rmpath 删除一条搜索路径 demo 运行Matlab演示程序 type 列出.M文 ...

最新文章

  1. Arduino学习笔记1---开发环境搭建
  2. Action 中 Response already committed 解决办法
  3. E: Could not get lock /var/lib/dpkg/lock解决
  4. Hadoop之InputFormat数据输入详解
  5. 字符串以及内存操作相关函数
  6. [js] 请使用js实现商品的自由组合,并说说你的思路
  7. jqGrid 中的editrules来自定义colModel验证规则
  8. 日语学习-多邻国-关卡1-介绍2
  9. c++中enum 如何使用(转)
  10. javascript模块 (Module) 简介
  11. 【深度学习】学习深度学习的最好方法
  12. layer 一些理解
  13. vs2019 product key
  14. 10月第3周安全回顾:恶意软件肆虐 Web安全重点关注
  15. 30+简约和平铺的WordPress复古主题
  16. MATLAB 排序函数(先按第一列排序(主排序)然后再按第二列排序(次排序))
  17. 站在巨人的肩膀上(转载)
  18. 用Python爬了我的微信好友,他们是这样的...
  19. oa项目经验描述_(完整版)简历中的项目经验范文
  20. 如何从Excel表格导入数据批量生成二维码

热门文章

  1. 你根本不懂rebase-使用rebase打造可读的git graph
  2. Ruby中如何识别13位的时间戳
  3. 本机Ajax异步通信
  4. python xml.dom模块解析xml
  5. 使用js命名空间进行模块式开发
  6. httpHandlers
  7. 如何使用你手中的利器
  8. [听尉迟方侃侃]平台
  9. linux手动同步文件命令,Linux文件同步命令rsync详解
  10. oracle commit session,Oracle session总结