Package pl.mkaczara.bch.decoder.worker

Source Code of pl.mkaczara.bch.decoder.worker.SimpleBCHDecoderWorker

package pl.mkaczara.bch.decoder.worker;

import pl.mkaczara.bch.math.BinPolynomial;
import pl.mkaczara.bch.code.CyclicCode;
import pl.mkaczara.bch.exception.UncorrectableErrorsException;

/**
* Klasa obiektow reprezentujacych workery uproszczonego dekodera BCH
*
* @author Michał
*/
public class SimpleBCHDecoderWorker extends AbstractBCHDecoderWorker {
   
    private Integer shifts = 0;
   
    /**
     * Tworzy nowy obiekt uproszczonego dekodera BCH
     *
     * @param code kod
     */
    public SimpleBCHDecoderWorker(CyclicCode code) {
        super(code);
    }

    @Override
    public BinPolynomial decode(BinPolynomial input) throws UncorrectableErrorsException {
        int w = 0;
        boolean permamentErrors = false;
       
        while (!permamentErrors) {
            BinPolynomial sx = input.modulo(getCode().getGenerator());
            w = getHammingWeight(sx);
            //Bledy w czesci kontrolnej
            if (w <= getCode().getT()) {
                //Korekta
                input = input.add(sx);
                //Przesuniecie cykliczne w lewo
                input.cyclicShiftVectorLeft(shifts);
                break;
            //Bledy w czesci informacyjnej
            } else {
                //Niekorygowalne
                if (shifts == getCode().getK()) {
                    permamentErrors = true;
                    break;
                //Przesuniecie cykliczne w prawo
                } else {
                    input.cyclicShiftVectorRight(1);
                    shifts++;
                }
            }
        }
       
        if(!permamentErrors){
            return getData(input);
        }
        throw new UncorrectableErrorsException();
    }

    @Override
    public Integer getComplexity() {
        //Miarą złożoności - liczba przesunięć
        return shifts;
    }

} // end SimpleBCHDecoderWorker
TOP

Related Classes of pl.mkaczara.bch.decoder.worker.SimpleBCHDecoderWorker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.