Do the functions FILTER2 and CONV2 perform correlation or convolution?

R
Ralph · Mar 22, 2021 · 2K views
Question
Do the functions FILTER2 and CONV2 perform correlation or convolution?  
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 23, 2026
The function FILTER2 performs correlation, while the function CONV2 performs convolution. To see what's going on, you need to compare the output of the 'full' option with the output of the 'valid' option. If you compare these two, you'll see that the 'valid' is taking the same submatrix in both cases. The full and valid matrices are actually not dependent on the values of "f".
 
For example:
 
 
a = magic(5)

 a =

     17    24     1     8    15

     23     5     7    14    16

      4     6    13    20    22

     10    12    19    21     3

     11    18    25     2     9

f = [1 0; 0 0];

filter2(f,a,'full')

 ans =

      0     0     0     0     0     0

      0    17    24     1     8    15

      0    23     5     7    14    16

      0     4     6    13    20    22

      0    10    12    19    21     3

      0    11    18    25     2     9

filter2(f,a,'valid')

 ans =

     17    24     1     8

     23     5     7    14

      4     6    13    20

     10    12    19    21
The 'valid' result is the (2:5,2:5) submatrix of the 'full' result.
 
 
g = [0 0; 0 1];

filter2(g,a,'full')

 ans =

     17    24     1     8    15     0

     23     5     7    14    16     0

      4     6    13    20    22     0

     10    12    19    21     3     0

     11    18    25     2     9     0

      0     0     0     0     0     0

filter2(g,a,'valid')

 ans =

      5     7    14    16

      6    13    20    22

     12    19    21     3

     18    25     2     9

Here also the 'valid' result is the (2:5,2:5) submatrix of the 'full' result.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!