日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Matlab 卷积函数 ——conv2

發布時間:2023/12/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Matlab 卷积函数 ——conv2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
功能:是二維卷積運算函數(與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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。