conv example

Upload: kshitij-gaur

Post on 03-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Conv Example

    1/5

    EEL 6562

    Image Processing & Computer Vision

    Linear and Circular Convolution Example

    Linear Convolution

    One dimensional linear discrete convolution is defined as:

    g(x) =

    s=

    f(s)h(x s) = f(x) h(x)

    For example, consider the convolution of the following two functions:

    1

    3

    1 1 1

    f(x)h(x)

    0 12

    3 0 1 2 3

    -2

    This convolution can be performed graphically by reflecting and shifting h(x),as shown in Figure 1. The samples off(s) and h(s x) that line up verticallyare multiplied and summed:

    g(0) =f(1)h(1) + f(0)h(0) = 0 + 1 = 1

    g(1) =f(0)h(1) + f(1)h(0) = 1 + 3 = 4

    g(2) =f(1)h(1) + f(2)h(0) = 3 + 2 = 1

    g(3) =f(2)h(1) + f(3)h(0) = 2 + 1 = 1

    g(4) =f(3)h(1) + f(4)h(0) = 1 + 0 = 1

    The result of the convolution is as shown below:

    1

  • 8/11/2019 Conv Example

    2/5

    1

    0 1 4

    g(x)

    4

    2

    1

    3

    1

    -1

    Notice that when f(x) is of length 4, and h(x) is of length 2, the linear convo-lution is of length 4 + 2 1 = 5.

    Circular Convolution

    One dimensional circular discrete convolution is defined as:

    g(x) =

    M1s=0

    f(s)h((x s) mod M) = f(x) h(x)

    ForM= 4, the convolution can be performed using circular reflection and shiftsofh(x), as shown in Figure 2. The samples off(s) andh((s x) mod M) thatline up vertically are multiplied and summed:

    g(0) =f(3)h(1) + f(0)h(0) = 1 + 1 = 2

    g(1) =f(0)h(1) + f(1)h(0) = 1 + 3 = 4

    g(2) =f(1)h(1) + f(2)h(0) = 3 + 2 = 1

    g(3) =f(2)h(1) + f(3)h(0) = 2 + 1 = 1

    The result of the convolution is as shown below:

    0 1

    g(x)

    4

    2

    1

    3

    -1

    2

    Notice that f(x) and h(x) are both treated as if they are of length 4, and the

    circular convolution is also of length 4.

    2

  • 8/11/2019 Conv Example

    3/5

    Linear Convolution as Circular Convolution

    Iff(x) andg(x) are both treated as if they are of length 4 + 2 1 = 5, then thefollowing circular convolution is calculated:

    g(0) =f(4)h(1) + f(0)h(0) = 0 + 1 = 1

    g(1) =f(0)h(1) + f(1)h(0) = 1 + 3 = 4

    g(2) =f(1)h(1) + f(2)h(0) = 3 + 2 = 1

    g(3) =f(2)h(1) + f(3)h(0) = 2 + 1 = 1

    g(4) =f(3)h(1) + f(4)h(0) = 1 + 0 = 1

    This procedure is called zero padding. Notice that this circular convolutionmatches the linear convolution.

    In general, if f(x) has length A, and h(x) has length B, and both f(x) andh(x) are zero padded out to length C, where C A + B 1, then the C-pointcircular convolution matches the linear convolution.

    3

  • 8/11/2019 Conv Example

    4/5

    1

    3

    1

    -1

    f(s)

    1

    -1

    1

    1

    3

    1

    -1

    f(s)

    1

    -1

    1

    3

    1

    -1

    f(s)

    -1

    1

    3

    1

    -1

    f(s)

    -1

    1

    3

    1

    -1

    f(s)

    -1

    1 1 1

    0 12

    3 4 0 12

    3 4 0 12

    3 4

    0 1 2 3 4 0 1 2 3 4 0 1 2 3 4

    0 12

    3 4 0 12

    3 4

    0 1 2 3 4 0 1 2 3 4

    11 11

    -2 -2 -2

    -2 -2

    h(0 s) h(1 s) h(2 s)

    h(3 s) h(4 s)

    Figure 1: Linear convolution by the graphical method.

    4

  • 8/11/2019 Conv Example

    5/5

    1

    3

    1

    0 12

    3

    1

    0 1 2 3

    f(s)

    1

    3

    1

    0 12

    3

    1

    0 1 2 3

    f(s)

    1

    1

    3

    1

    0 12

    3

    0 1 2 3

    f(s)

    1

    3

    1

    0 12

    3

    0 1 2 3

    f(s)

    1

    1

    1 1 1

    -2 -2

    -2 -2

    h((0 s) mod 4) h((1 s) mod 4)

    h((2 s) mod 4) h((3 s) mod 4)

    Figure 2: Circular convolution using the graphical method.

    5