转自:https://blog.csdn.net/dkcgx/article/details/46652021

转自:https://blog.csdn.net/Reborn_Lee/article/details/83279843

conv(向量卷积运算)
所谓两个向量卷积,说白了就是多项式乘法。 比如:p=[1 2 3],q=[1 1]是两个向量,p和q的卷积如下: 把p的元素作为一个多项式的系数,多项式按升幂(或降幂)排列,比如就按升幂吧,写出对应的多项式:1+2x+3x^2;同样的,把q的元素也作为多项式的系数按升幂排列,写出对应的多项式:1+x。
卷积就是“两个多项式相乘取系数”。 (1+2x+3x^2)×(1+x)=1+3x+5x^2+3x^3 所以p和q卷积的结果就是[1 3 5 3]。
记住,当确定是用升幂或是降幂排列后,下面也都要按这个方式排列,否则结果是不对的。 你也可以用matlab试试 p=[1 2 3] q=[1 1] conv(p,q) 看看和计算的结果是否相同。
conv2(二维矩阵卷积运算)
a=[1 1 1;1 1 1;1 1 1]; b=[1 1 1;1 1 1;1 1 1]; >> conv2(a,b)
ans =
     1     2     3     2     1

2     4     6     4     2

3     6     9     6     3

2     4     6     4     2

1     2     3     2     1
>> conv2(a,b,'valid')
ans =
     9
>> conv2(a,b,'same')
ans =

4     6     4

6     9     6

4     6     4
>> conv2(a,b,'full')
ans =

1     2     3     2     1

2     4     6     4     2

3     6     9     6     3

2     4     6     4     2

1     2     3     2     1

convn(n维矩阵卷积运算)

>> a=ones(5,5,5)
a(:,:,1) =

1     1     1     1     1

1     1     1     1     1

1     1     1     1     1

1     1     1     1     1

1     1     1     1     1
a(:,:,2) =
     1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1
a(:,:,3) =
     1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1
a(:,:,4) =
     1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1
a(:,:,5) =
     1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1      1     1     1     1     1
>> b=ones(5,5,5);
>> convn(a,b,'valid')
ans =
   125
>> convn(a,b,'same')
ans(:,:,1) =
    27    36    45    36    27

36    48    60    48    36

45    60    75    60    45

36    48    60    48    36

27    36    45    36    27
ans(:,:,2) =
    36    48    60    48    36     48    64    80    64    48     60    80   100    80    60     48    64    80    64    48     36    48    60    48    36
ans(:,:,3) =
    45    60    75    60    45     60    80   100    80    60     75   100   125   100    75     60    80   100    80    60     45    60    75    60    45
ans(:,:,4) =
    36    48    60    48    36     48    64    80    64    48     60    80   100    80    60     48    64    80    64    48     36    48    60    48    36
ans(:,:,5) =
    27    36    45    36    27     36    48    60    48    36     45    60    75    60    45     36    48    60    48    36     27    36    45    36    27
>> convn(a,b)
ans(:,:,1) =
     1     2     3     4     5     4     3     2     1

2     4     6     8    10     8     6     4     2

3     6     9    12    15    12     9     6     3

4     8    12    16    20    16    12     8     4

5    10    15    20    25    20    15    10     5

4     8    12    16    20    16    12     8     4

3     6     9    12    15    12     9     6     3

2     4     6     8    10     8     6     4     2

1     2     3     4     5     4     3     2     1
ans(:,:,2) =
     2     4     6     8    10     8     6     4     2      4     8    12    16    20    16    12     8     4      6    12    18    24    30    24    18    12     6      8    16    24    32    40    32    24    16     8     10    20    30    40    50    40    30    20    10      8    16    24    32    40    32    24    16     8      6    12    18    24    30    24    18    12     6      4     8    12    16    20    16    12     8     4      2     4     6     8    10     8     6     4     2
ans(:,:,3) =
     3     6     9    12    15    12     9     6     3      6    12    18    24    30    24    18    12     6      9    18    27    36    45    36    27    18     9     12    24    36    48    60    48    36    24    12     15    30    45    60    75    60    45    30    15     12    24    36    48    60    48    36    24    12      9    18    27    36    45    36    27    18     9      6    12    18    24    30    24    18    12     6      3     6     9    12    15    12     9     6     3
ans(:,:,4) =
     4     8    12    16    20    16    12     8     4      8    16    24    32    40    32    24    16     8     12    24    36    48    60    48    36    24    12     16    32    48    64    80    64    48    32    16     20    40    60    80   100    80    60    40    20     16    32    48    64    80    64    48    32    16     12    24    36    48    60    48    36    24    12      8    16    24    32    40    32    24    16     8      4     8    12    16    20    16    12     8     4
ans(:,:,5) =
     5    10    15    20    25    20    15    10     5     10    20    30    40    50    40    30    20    10     15    30    45    60    75    60    45    30    15     20    40    60    80   100    80    60    40    20     25    50    75   100   125   100    75    50    25     20    40    60    80   100    80    60    40    20     15    30    45    60    75    60    45    30    15     10    20    30    40    50    40    30    20    10      5    10    15    20    25    20    15    10     5
ans(:,:,6) =
     4     8    12    16    20    16    12     8     4      8    16    24    32    40    32    24    16     8     12    24    36    48    60    48    36    24    12     16    32    48    64    80    64    48    32    16     20    40    60    80   100    80    60    40    20     16    32    48    64    80    64    48    32    16     12    24    36    48    60    48    36    24    12      8    16    24    32    40    32    24    16     8      4     8    12    16    20    16    12     8     4
ans(:,:,7) =
     3     6     9    12    15    12     9     6     3      6    12    18    24    30    24    18    12     6      9    18    27    36    45    36    27    18     9     12    24    36    48    60    48    36    24    12     15    30    45    60    75    60    45    30    15     12    24    36    48    60    48    36    24    12      9    18    27    36    45    36    27    18     9      6    12    18    24    30    24    18    12     6      3     6     9    12    15    12     9     6     3
ans(:,:,8) =
     2     4     6     8    10     8     6     4     2      4     8    12    16    20    16    12     8     4      6    12    18    24    30    24    18    12     6      8    16    24    32    40    32    24    16     8     10    20    30    40    50    40    30    20    10      8    16    24    32    40    32    24    16     8      6    12    18    24    30    24    18    12     6      4     8    12    16    20    16    12     8     4      2     4     6     8    10     8     6     4     2
ans(:,:,9) =
     1     2     3     4     5     4     3     2     1      2     4     6     8    10     8     6     4     2      3     6     9    12    15    12     9     6     3      4     8    12    16    20    16    12     8     4      5    10    15    20    25    20    15    10     5      4     8    12    16    20    16    12     8     4      3     6     9    12    15    12     9     6     3      2     4     6     8    10     8     6     4     2      1     2     3     4     5     4     3     2     1

conv

Convolution and polynomial multiplication

Syntax

w = conv(u,v)

w = conv(u,v,shape)

Description

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

w = conv(u,v,shape) returns a subsection of the convolution, as specified by shape. For example, conv(u,v,'same') returns only the central part of the convolution, the same size as u, and conv(u,v,'valid') returns only the part of the convolution computed without the zero-padded edges.

w = conv(u,v,shape)返回卷积的子部分,由形状指定。 例如,conv(u,v,'same')仅返回卷积的中心部分,与u的大小相同,而conv(u,v,'valid')仅返回计算后的卷积部分而没有零填充边。


Polynomial Multiplication via Convolution

Create vectors u and v containing the coefficients of the polynomials x^2 + 1 and 2x + 7.

u = [1 0 1];
v = [2 7];

Use convolution to multiply the polynomials.

w = conv(u,v)
w = 1×4

     2     7     2     7

w contains the polynomial coefficients for  2x^3 + 7x^2 + 2x + 7.


Vector Convolution

Create two vectors and convolve them.

u = [1 1 1];
v = [1 1 0 0 0 1 1];
w = conv(u,v)
w = 1×9

     1     2     2     1     0     1     2     2     1

The length of w is length(u)+length(v)-1, which in this example is 9.


Central Part of Convolution

Create two vectors. Find the central part of the convolution of u and v that is the same size as u.

u = [-1 2 3 -2 0 1 2];
v = [2 4 -1 1];
w = conv(u,v,'same')
w = 1×7

    15     5    -9     7     6     7    -1

w has a length of 7. The full convolution would be of length length(u)+length(v)-1, which in this example would be 10.



matlab中卷积convolution与filter用法的更多相关文章

  1. matlab中norm与svd函数用法

    格式:n=norm(A,p) 功能:norm函数可计算几种不同类型的矩阵范数,根据p的不同可得到不同的范数 以下是Matlab中help norm 的解释: NORM Matrix or vector ...

  2. MATLAB中的max函数的用法及含义

    当A是一个列向量时候,返回一个最大值,在此不在赘述. 当Amxn是一个矩阵的时候,有以下几种情况: ①   C = max(max(A)),返回矩阵最大值 ②   D = max(A,[],1),返回 ...

  3. matlab中卷积编码参数的理解

    poly2trellis(7, [171 133])代表什么意思呢?首先是7,他是1*k的vector,此处k为1,[171 133]是k*n的vector,此处n就是2,那么这个编码就是1/2码率的 ...

  4. matlab中disp函数的简单用法

    输出数组类型的数据,也可以把string类型的数据看做数组输出 输出数字 >> num = ; >> disp(num) 输出字符串 >> disp('this i ...

  5. matlab中的卷积——filter,conv之间的区别

    %Matlab提供了计算线性卷积和两个多项式相乘的函数conv,语法格式w=conv(u,v),其中u和v分别是有限长度序列向量,w是u和v的卷积结果序列向量. %如果向量u和v的长度分别为N和M,则 ...

  6. 图像卷积、相关以及在MATLAB中的操作

    图像卷积.相关以及在MATLAB中的操作 2016年7月11日 20:34:35, By ChrisZZ 区分卷积和相关 图像处理中常常需要用一个滤波器做空间滤波操作.空间滤波操作有时候也被叫做卷积滤 ...

  7. matlab中fspecial Create predefined 2-D filter以及中值滤波均值滤波以及高斯滤波

    来源: 1.https://ww2.mathworks.cn/help/images/ref/fspecial.html?searchHighlight=fspecial&s_tid=doc_ ...

  8. Matlab中imfilter()函数的用法

    Matlab中imfilter()函数的用法 功能:对任意类型数组或多维图像进行滤波.用法:B = imfilter(A,H) B = imfilter(A,H,option1,option2,... ...

  9. MATLAB中conv2的详细用法 (以及【matlab知识补充】conv2、filter2、imfilter函数原理)

    转载: 1.https://blog.csdn.net/jinv5/article/details/52874880 2.https://blog.csdn.net/majinlei121/artic ...

随机推荐

  1. Burst

    Unity Burst 用户指南 https://blog.csdn.net/alph258/article/details/83997917 Burst https://unity3d.com/cn ...

  2. 【平台开发】— 8.前端-从[项目管理]来看vue

    现在要来实现[项目管理]这个功能了. 想象一下页面,元素大概就是:列表页.查询框.新增按钮.编辑.mock入口按钮. 那先来实现列表和新建,也顺带着整理一下用到的vue相关指令知识. 一.后端 后端就 ...

  3. linux下P2P协议(BitTorrent)-libtorrent库编译,测试

    1.libtorrent 简介,下载和编译 libtorrent简介 libtorrent是功能齐全的C ++ bittorrent的p2p协议实现,专注于效率和可伸缩性.它可以在嵌入式设备和台式机上 ...

  4. css3渐变色实现小功能 ------ css(linaer-gradient)

    由沿直线两种或多种颜色之间的渐进转换的图像.它的结果是数据类型的对象,这是一种特殊的类型. 与任何梯度一样,线性梯度没有内在维度 ; 即,它没有天然或优选的尺寸,也没有优选的比例.其具体尺寸将与其适用 ...

  5. 如何让Web程序在点击按钮后出现如执行批处理程序般的效果

    在cli程序中,输入命令得到连续的输出已经是一种进度而美观的页面交互形式,好比下图: 而web程序里也有类似的场景,比如执行一个耗时任务,除了显示出等待图标外,用户还希望把执行的状态及时显示出来.如下 ...

  6. Redis windows版安装测试

    1.下载 下载地址是 https://github.com/microsoftarchive/redis/releases/tag/win-3.2.100 ,我选择的是Redis-x64-3.2.10 ...

  7. 原生JDK网络编程- Buffer

    Buffer用于和NIO通道进行交互.数据是从通道读入缓冲区,从缓冲区写入到通道中的.以写为例,应用程序都是将数据写入缓冲,再通过通道把缓冲的数据发送出去,读也是一样,数据总是先从通道读到缓冲,应用程 ...

  8. python应用 曲线拟合 01

    双指数函数 待拟合曲线为 y(x) = bepx + ceqx import matplotlib.pyplot as plt x = ([0.05, 0.1, 0.15, 0.2, 0.25, 0. ...

  9. Android 4.X 系统加载 so 失败的原因分析

    1 so 加载过程 so 加载的过程可以参考小米的系统工程师的文章loadLibrary动态库加载过程分析 2 问题分析 2.1 问题 年前项目里新加了一个 so库,但发现native 方法的找不到的 ...

  10. linux系统漏洞扫描工具lynis

    lynis 是一款运行在 Unix/Linux 平台上的基于主机的.开源的安全审计软件.Lynis是针对Unix/Linux的安全检查工具,可以发现潜在的安全威胁.这个工具覆盖可疑文件监测.漏洞.恶意 ...