Affine Projection Algorithm David Straight

Embed Size (px)

Citation preview

  • 7/31/2019 Affine Projection Algorithm David Straight

    1/14

    Page 1 of 14

    AFFINE PROJECTION ALGORITHM: VARIATIONS AND

    APPLICATION TO 2-D IMAGE PROCESSING

    David A. Straight, Santa Clara University

    ABSTRACT

    A two dimensional affine projection algorithm has

    been realized by augmenting a one dimensional affine

    projection algorithm using a two dimensional state

    equation. Application of the algorithm was then applied

    to an interference cancellation configuration for image

    processing. Convergence behavior was briefly explored

    in simulation to show how numerical errors influence

    minimum mean squared error.

    1. INTRODUCTION

    Interference in a system has the potential to degradeperformance and therefore it would be advantageous to

    remove the interfering signal by some means. Simple

    subtraction of such a signal is attractive when an exact

    copy of the interference signal is known or available. In

    many systems the interfering source is known, but an

    exact copy is not realizable or varies over time. Some

    examples would include adjacent transmitters and

    receivers that must operate simultaneously and medical

    imaging systems such as MRI and ultrasound. Adaptive

    filtering is a viable solution to this type of interference

    since, quite often, the interfering source is available. A

    few examples of this include 60Hz interference,

    mechanical vibration, magnetic fluctuation anddisturbance of power supply lines. In an MRI system any

    of these disturbances can degrade the resultant image due

    to the sensitivity of the system as a whole. This paper

    provides a method for cancelling noise in two

    dimensional images.

    There are five sections in this article. 1) the introduction

    2) methods for developing the algorithm 3) results of

    simulation 4) MATLAB code used and 5) references

    used.

    Notation used

    ),( nmy scalar (also a function ofm and n)

    ),( nmw vector (also a function ofm and n)

    ),( nmY matrix (also a function ofm and n)

    knu a vector that is a function ofkand n

    T)( transpose operator

    2.1 IMPLEMENTATION OF 2D APA

    A two dimensional convolution of the form

    = =

    =M

    i

    N

    j

    jnimnmnm1 1

    ),(),(),( WXY

    can be represented as

    ),(),(),( nmwnmxnmyT

    =

    where is a single element of and

    and have been mapped into column-

    ordered vectors

    ),( nmy ),( nmY),( nmX ),( nmW

    ),( nmx and ),( nmw respectively [6] as

    shown below.

    =

    =

    ),(

    )1,3(

    ),2(

    )1,2(),1(

    )3,1(

    )2,1(

    )1,1(

    ),(,

    ),(

    ),2(

    ),1(

    ),1(),(

    )2,(

    )1,(

    ),(

    ),(

    NNw

    w

    Nw

    wNw

    w

    w

    w

    nmw

    NnNmx

    nmx

    Nnmx

    nmxNnmx

    nmx

    nmx

    nmx

    nmx

    M

    M

    M

    M

    M

    M

  • 7/31/2019 Affine Projection Algorithm David Straight

    2/14

    Page 2 of 14

    After mapping a block of data of size N x N to a column

    vector of size N2 x 1 the affine projection algorithm can

    be implemented as two one dimensional algorithms that

    update the weight equation along the horizontal and

    vertical directions. Updating the weights along both

    horizontal and vertical directions is what makes this a true

    two dimensional algorithm [2]. Because of the vector

    mapping Gram Schmidt orthogonalization is no different

    than the one-dimensional case.

    For the one dimensional case Sankaran [1] uses the

    following weight update equation

    M

    nMnnnn uuuww ++++=+ L1

    1

    0

    01

    Where,

    1

    +nw is the updated weight.

    nw is the previous weight.M10

    nnn uuu ,,, L are a set of vectors all orthogonal

    to each other.

    M ,,, 10 L are functions of the error and data

    Mkfor

    u

    e

    k

    n

    nk

    ,,2,1,0

    2

    L=

    =

    k

    The error function isk

    n

    T

    knkn

    k

    n wxde = . The

    superscript, k, in the weight vector, knw , represents the

    estimated weight vector generated for each

    orthogonalized vectork

    nu , using

    kkk+1

    nknn uww += ++ 11 where00

    nn xu = . and

    Mknu L3,2,1,0for =k

    are vectors that are orthogonal to

    each other and originate from the set of data vectors

    Mnnnn xxxx L,,, 21 using the Gram Schmidt

    process as described by [8].

    Following the work of Ohiki & Hashiguchi [2] as well as

    Pinto [7] a two dimensional algorithm using a twodimensional state equation gives

    M

    MvMv

    M

    MhMhnvvnhh

    nvvnhh

    nmvnmhnm

    uuuu

    xx

    wfwfw

    ,,,,

    1

    ,1,

    1

    ,1,

    0

    ,0,

    0

    ,0,

    ,11,1,1

    ++++

    ++

    += ++++

    L

    Where,

    h and v represent horizontal and vertical respectively

    are constants related byvh ff and, 1=+ vh ff

    nmnm ww ,11, and ++ are the weight update vectors

    updated along the horizontal and

    vertical directions respectfully

    As pointed out by Ohiki and Hashiguchi [2] both

    nmnm ww ,11, and ++ are updated in one dimension along

    the horizontal and vertical directions respectively and this

    is why the following equations are considered one

    dimensional even though they operate on two dimensionaldata

    vh ff and, are the state equations.

  • 7/31/2019 Affine Projection Algorithm David Straight

    3/14

    Page 3 of 14

    2.2 - ALGORITHM CHART

    (1)nh

    T

    nhnhnh wxde ,,,, =

    nv

    T

    nvnvnv wxde ,,,, =

    (2)nh

    T

    nhnh xxx ,,2

    , =

    nv

    T

    nvnv xxx ,,2

    ,=

    (3)

    2

    ,

    ,

    ,0

    nh

    nh

    nh

    x

    e =

    2

    ,

    ,

    ,0

    nv

    nv

    nv

    x

    e =

    (4)nhnhnh xww ,0,

    1

    1, +=+

    nvnvnv xww ,0,1

    1, +=+

    (5)

    nhnh

    xu,

    0

    ,

    =

    nvnv xu ,0

    , =

    For k = 1,2,3 M repeat steps (6) through (9)

    (6)

    =

    =

    1

    0

    ,2

    ,

    ,,

    ,,

    k

    i

    i

    nhi

    nh

    i

    nh

    T

    knh

    knh

    k

    nh u

    u

    uxxu

    =

    =

    1

    0

    ,2

    ,

    ,,

    ,,

    k

    i

    i

    nvi

    nv

    i

    nv

    T

    knv

    knv

    k

    nv uu

    uxxu

    (7)nh

    T

    knhknh

    k

    nh wxde ,,,, =

    nv

    T

    knvknv

    k

    nv wxde ,,,, =

    (8)

    =

    else

    uif

    u

    e knh

    k

    nh

    k

    nh

    kh

    0

    02

    ,2

    ,

    ,

    ,

    =

    else

    uifu

    e knv

    k

    nv

    k

    nv

    kv

    0

    02

    ,2

    ,

    ,

    ,

    (9) knhk

    k

    nh

    k

    nh uww ,1,1

    1, += +

    ++

    k

    nvk

    k

    nv

    k

    nv uww ,1,1

    1, += +

    +

    +

    (10) 11,1,

    +

    ++ =M

    nhnh ww

    1

    1,1,

    +

    ++ =M

    nvnv ww

    The chart to the left shows every step needed to perform

    the affine projection algorithm.

    Figure 1 and Figure 2 provide an example of how data is

    gathered from the original data. For this example M=2.

    The horizontal data set at any iteration, n, is

    . The diagram below showsfor the black, blue and green dashed

    rectangles respectively.

    MkforL

    3,2,1,0k-nm,=

    X2,22,32,4 ,, XXX

    n

    m

    Index 1,1x(1,1)

    2D Image

    direction of

    weight update

    horizontal

    Figure 1

    Similarly, denotes data for

    iteration m. The diagram below is shown for

    for the black, blue and green dashed

    rectangles respectively.

    Mkfor L3,2,1,0nk,-m =X

    2,23,24,2 ,, XXX

    Index 1,1x(1,1)

    n

    m

    direction of

    weight updatevertical

    Figure 2

    Column ordered vectors are formed from and

    giving

    k-nm,X

    nk,-mX nhx , and nvx , respectively as seen in the

    algorithm chart on the left.

  • 7/31/2019 Affine Projection Algorithm David Straight

    4/14

    Page 4 of 14

    2.3 NOISE REDUCTION

    Following a simple derivation from Widrow [5] we showhow an interference cancellation circuit using an adaptive

    filter works. Figure 3 shows an application for this

    adaptive filter as a noise canceling circuit. In the diagramwe have a signal, s, that has been contaminated with

    noise, n, where n is not correlated with s. n and s have

    zero mean.

    +

    AdaptiveFilter

    +

    -

    e

    y

    System

    output

    H

    2

    nwith variance

    nnoise

    2

    H

    2)var( yy =

    Input Imagecontaminated

    with noise

    ns +22

    ns +with variance

    Figure 3

    By first taking the z transform of the autocorrelation of

    the noise and signal and then forming a ratio of signal tonoise ratios between the output and input. Letting

    )(zout represent the signal to noise ratio of the system

    output and )(zin represent the signal to noise ratio of

    the input contaminated by noise the improvement in

    signal to noise ration is then found by [5]

    [ ]2)()(1)(

    )(

    )(

    )(

    )(

    )(

    zWzHz

    z

    z

    z

    z

    z

    nn

    nn

    noiseoutput

    nn

    in

    out

    =

    =

    Where,

    is the power spectral density of the

    interfering signal

    is the noise power spectral

    density at the output.

    is the transfer function of the adaptive

    filter.

    )(znn

    )(znoiseoutput

    )(zW

    When the adaptive filter converges then )(1)( zHzW = and the denominator of the above equation will go to zero

    making the output signal to noise ratio infinitely large.

    Of course there are other sources of noise that preventinfinite improvement. In this simple diagramH(z)

    represents an unknown channel that provides a correlated

    source to the original interferer, but not an exact copy of

    the noise. The adaptive filter helps by inverse modeling

    this channel and upon doing so provides the exact copy

    (for the noisless case) of the correlated disturbance.

    2.4 CONVERGENCE

    There are many resources (papers) available on the topic

    of convergence [1]. This paper is not about convergence,however a few simple formulas for specific cases are

    provided as a convenience here. From Sankaran [1] the

    flowing relationships were derived on the assumption is

    that white Gaussian noise with zero mean was used as theinput.

    The convergence rate is approximately

    [ ])1/(5dB20

    +

    MN

    The minimum mean squared error.

    += R)tr(

    )(

    11

    2

    2

    nxEMMSE v

    3.1 - MSE learning curves

    Prior to application of a noise cancelling system the

    simulation was tested to verify proper operation

    The algorithm was simulated in a system identification

    configuration as shown in Figure 4 below.

    Adaptive

    Filter

    xinput

    +

    -

    e

    d

    Plant

    y

    +

    +

    +

    +

    output

    additive

    noisen

    12=x

    20210

    =n

    Figure 4

    Initial results for eight simulations appear in Figure 5.

    Simulation of the two dimensional affine projection

    algorithm show the benefit of faster convergence with theaddition of additional orthogonal data vectors. The impact

  • 7/31/2019 Affine Projection Algorithm David Straight

    5/14

  • 7/31/2019 Affine Projection Algorithm David Straight

    6/14

  • 7/31/2019 Affine Projection Algorithm David Straight

    7/14

    Page 7 of 14

    )(2)( 222 yndynd ++=

    ])[(][

    )]([2])[(][][

    22

    222

    ynEdE

    yndEynEdEE

    +=

    ++=

    The second term on the right hand side of the equation isthe only term minimized by the adaptive filter leaving the

    power of the uncontaminated alone. This is the basis of

    how this type of system works.

    In simulation is estimated by squaring the error

    and averaging over the number of iterations performed.

    The error term was generated using

    ][ 2E

    1,1

    ++ nmw in the

    following error equation.

    1,1, ++=nm

    T

    nmn wxde

    Where, is a given pixel of the imagemnd ,

    1,1

    ++ nmw is the adaptive weight

    coefficient of a 2D mask (that has been

    mapped as a vector (described insection 2.1 and 2.2)

    Figure 11 shows the test image representing . The

    variance of is 0.01.

    0nd+

    0n

    Figure 12 and Figure 13 are two examples of noiseremoved from the original picture ofFigure 11. For eachof these pictures 2000 iterations were run, in Figure 12

    M=1and in Figure 13 M=3.

    Figure 11 Image corrupted by noise (variance of the addednoise was 0.01)

    Figure 12 2000 iterations, M=1

    Figure 13 2000 iterations, M=3

    The simulation ofFigure 12 had the following estimatedweight values.

    =

    0234.00330.00010.0

    0310.09657.00158.0

    0530.00447.00112.0

    W

    The simulation ofFigure 13 had the following estimated

    weight values.

    =

    0602.00033.00493.0

    0285.09812.00789.0

    0634.00257.00051.0

    W

    It is easy to see (and prove) that the ideal weights would

    be an impulse of the form

    =

    000

    010

    000

    oW

  • 7/31/2019 Affine Projection Algorithm David Straight

    8/14

    Page 8 of 14

    simply because a simple subtraction will remove allnoise, perfectly because no = n1 (assuming a perfectly

    linear process).

    0=+= ynde

    Therefore we would need ny = , but since n was fedinto the adaptive filter then an impulse response would bean appropriate coefficient.

    3.3 CLIPPING

    Distortion in a system can prevent a cancellation

    system from working properly. This was discoveredduring simulation in the image shown in Figure 14.

    Limited by the dynamic range of the system both the

    noise and the image exceeded a maximum limit leading

    to clipping of the image. This occurred in areas where

    the nose and mouth of the pumpkin are located. In theseareas, information was lost during the process of adding

    noise resulting in loss of noise in these regions.

    Without the added noise the adaptive circuit minimized

    these areas

    Figure 15

    3.4 CONCLUSION

    An application for a two dimensional affine algorithm was

    developed and simulated for the purpose of noise

    cancellation. The Affine algorithm is well suited for this

    purpose because of its convergence speed even with highlycorrelated inputs commonly found in images. The adaptive

    filter has the ability to channel equalize the path of the

    noise source making it suitable for image processing inchanging environments. Applying image enhancement

    using this algorithm would benefit systems such as MRI

    that fall vulnerable to disturbances of known origin, but

    unknown channel paths. It was found through oursimulations that limits in dynamic range as well as

    numerical computation can influence overall system

    design of an adaptive 2D image interference cancellationsystem.

    Figure 14

  • 7/31/2019 Affine Projection Algorithm David Straight

    9/14

    Page 9 of 14

    4.1 MATLAB CODE (2D AFFINE)

    % 2D Affine Application to image processing - interference cancellation%

    % for best results set the variable "times" to 1000, however this will take

    % a very long time therefore it is recommended that lower values be used.% times=100 will take about 15 minutes to run.

    close all;

    clear all;

    fh = 0.5;

    fv = 1-fh;

    % getimpage() is a function that loads an image with noise

    % into the first element of the row vector (d) and the noise used

    % to contaminate the image into the second element(x).

    [clnImg d x] = getimage();

    L=size(d)*[1;0]; % lenth of input data (horz. & vert.)

    % == Filter settingsN=3 ; % horz. & vert. length of vector x (w & wo are size NxN)

    % N must be odd

    mu = 1; % set to 0 < mu < 2 (mu=1 is best)

    r = (N-1)/2; %used repeatedly

    %represents "pixel" lost around perimeter of X upon%convolving using 'valid' command in conv2()

    s = (N+1)/2; % used repeatedly (center of mask)

    error = zeros(L,L); %

    wav = zeros(N*N,1);% == averaging learning curves

    times = 100;

    % == filter setting

    M=1; % number of orthogonal vectors used (total number of orthogonal vectors is M+1

    mse=zeros(L*L,1);

    for t=1:times; % this loop used for averaging learning curve == t Loop

    % == initialize variables, vectors and matices

    sqmagXh = 0;

    sqmagXv = 0;w=zeros(N*N,1); %initialize adaptive weights

    wh=zeros(N*N,1);

    wv=zeros(N*N,1);wtemp=zeros(N*N,1); % used for Gram Schmidt calculation

    Uh=zeros(N*N,1); % M orthogonal vectors (length N)

    Uv=zeros(N*N,1); % M orthogonal vectors (length N)

    wtemph=zeros(N*N,1);wtempv=zeros(N*N,1);

  • 7/31/2019 Affine Projection Algorithm David Straight

    10/14

    Page 10 of 14

    temph=zeros(N*N,1);

    tempv=zeros(N*N,1);

    [clnImg d x] = getimage();

    %flipud(fliplr())

    c=0; % used for averaging mse (learning) curve - counts total interations

    for n=s+M:L-r %=== loop 1 ===

    for m=s+M:L-r

    xhvec = reshape(x(m-r-M:m+r-M,n-r:n+r), N*N, 1);

    eh = d(m-M,n) - xhvec'*wh;

    xvvec = reshape(x(n-r:n+r,m-r-M:m+r-M), N*N, 1);

    ev = d(n,m-M) - xvvec'*wv;

    sqmagXh = xhvec'*xhvec; % (2h)

    sqmagXv = xvvec'*xvvec; % (2v)

    muoh = (mu*eh)/sqmagXh; %(3h)muov = (mu*ev)/sqmagXv; %(3v)

    wtemph = wh + muoh*xhvec; % temp weight vector %(4h)

    wtempv = wv + muov*xvvec; % temp weight vector %(4v)

    Uh(:,1) = xhvec; %(5h) first of M+1 orthogonal vectors

    Uv(:,1) = xvvec; %(5v)

    for k=1:M % if M>0 then the algorithm is Affine, otherwise it is NLMS

    % if you plan to use M=0 then you must add an if

    % condition so that the program does not enter

    % into this loop.

    % ======== Begin (6) =========for i=1:k % == Gram-Schmidt -- begin --

    xhvec = reshape(x(m-r-M:m+r-M,n-r-k:n+r-k), N*N, 1);temph = temph + (( xhvec'*Uh(:,i) ) / (Uh(:,i)'*Uh(:,i) + 10^-100))*Uh(:,i);

    xvvec = reshape(x(n-r-k:n+r-k,m-r-M:m+r-M), N*N, 1);

    tempv = tempv + (( xvvec'*Uv(:,i) ) / (Uv(:,i)'*Uv(:,i) + 10 -100))*Uv(:,i);end %== Gram-Schmidt -- end --

    Uh(:,k+1) = xhvec - temph;

    Uv(:,k+1) = xvvec - tempv;

    temph = zeros(N*N,1);

    tempv = zeros(N*N,1);

    % ======== End (6) =========

    eh = d(m-M,n-k) - xhvec'*wtemph; %(7)ev = d(n-k,m-M) - xvvec'*wtempv;

    UmagSqh = Uh(:,k+1)'*Uh(:,k+1);

    UmagSqv = Uv(:,k+1)'*Uv(:,k+1);

  • 7/31/2019 Affine Projection Algorithm David Straight

    11/14

    Page 11 of 14

    if UmagSqh ~= 0 %(8h)

    mu0h = (mu*eh)/UmagSqh;else

    mu0h = 0 ;

    end

    if UmagSqv ~= 0 %(8v)

    mu0v = (mu*ev)/UmagSqv;

    else

    mu0v = 0 ;end

    wtemph = wtemph + mu0h*Uh(:,k+1); % (9h)wtempv = wtempv + mu0v*Uv(:,k+1); % (9v)

    end % end k Loop (same as loop 2)wh = wtemph;

    wv = wtempv;

    wtemph = zeros(N*N,1);wtempv = zeros(N*N,1);

    evh = d(m,n) - reshape(x(m-r:m+r,n-r:n+r),N*N,1)'*w;c=c+1;

    error(m,n) = error(m,n) + evh;

    w = wh*fh + wv*fv; % update equation - left side is w(1+n) (10)

    end % == end m loop (part of loop 1)

    % initialize variables before next n (and m) or iteration

    end% end n loop (part of loop 1) loop 1 has ended

    wav = wav + w;w = wav./t;

    end% end loop t

    % graphs go here

    wav = wav./times; %average weight coefficient

    error = error./times; %average MSE

    colormap('gray')

    ma = max(max(error));

    mi = min(min(error));error = error./(ma-mi);

    error = error - min(min(error));error = error*64;subplot(2,2,1)

    image(error)

    title('adaptive filter')

    subplot(2,2,2)

    image(d*50)

    title('original picture contaminated by noise')

  • 7/31/2019 Affine Projection Algorithm David Straight

    12/14

    Page 12 of 14

    temp = conv2(d,ones(3,3)*(1/9));

    ma = max(max(temp));mi = min(min(temp));

    temp = temp./(ma-mi);

    temp = temp - min(min(temp));temp = temp*64;

    subplot(2,2,3)

    image(temp)

    title('picture processed with a LPF')

    subplot(2,2,4)

    image(clnImg*0.23)

    title('pure image')

  • 7/31/2019 Affine Projection Algorithm David Straight

    13/14

  • 7/31/2019 Affine Projection Algorithm David Straight

    14/14

    Page 14 of 14

    5.1 - REFERENCE

    [1] Sankaran, S.G., Beex, A.L., "Convergence Behavior

    of Affine Projection Algorithms,'' IEEE Transactions onSignal Processing, vol. 48, No. 4, pp. 10861096, April

    2000.

    [2] Makoto Ohki, Sumihisa Hashiguchi, "Two-

    dimensional LMS Adaptive Filters,'' IEEE Transactions

    on Consumer Electronics, vol. 37, No. 1, pp. 6673, Feb.

    1991.

    [3] Slock, Dirk T.M., "On the Convergence Behavior of

    LMS and NLMS Algorithms,'' IEEE Transactions on

    Signal Processing, vol.41, pp. 2811-2825, Sept. 1993.

    [4] R. C. Gonzalez, R. E. Woods, Digital Image

    Processing, second edition Upper Saddle River, N.J.07458, Prentice Hall, 2002

    [5] B. Widrow, S. Stearns, Adaptive Signal Processing

    Englewood Cliffs, N.J. 0763: Prentice-Hall, Inc.1985

    [6] Strait, Jenkins Orthogonalization Techniques forTwo-Dimensioanl Adaptive Fitlers CoordinatedCoordinated Science Laboratory, University of Illinois,

    Urbana, IL 61801

    [7] S. S. Pinto Convergence Behavior of 2-Dimensional

    Affine Projection Algorithms, MSEE Thesis, Santa ClaraUniversity, Santa Clara, CA 95053.

    [8] G. H. Golub, C. F. Van Loan, Matrix computations -

    third edition The Johns Hopkins University Press,

    Baltimore, Maryland, 21218-4319, The Johns HopkinsUniversity Press