Литература - Построение декодера Рида - Маллера

    1. Блейхут Р. Теория и практика кодов, контролирующих ошибки. Москва: Мир, 1986 г. 2. Мак-Вильямс Ф. Дж., Слоэн Н. Дж. А. Теория кодов, исправляющих ошибки. М.: Связь, 1979 г. 3. Дмитриев В. И. Пр-кладная теория информации. М.: Высшая школа, 1989г. 4. Дж. Кларк, Дж. Кейн. Кодирование с исправлением ошибок в системах цифровой связи. М.: Радиосвязь, 1987 г. 5. Круглински Девид Дж., Основы Visual C++/Пер. с англ. - М.: Издательский отдел "Русская редакция", 1997 г.

Приложение

Файл Rid. h

// Decoder Rid. h : main header file for the DECODER RID application

//

#if! defined(AFX_DECODERRID_H__C9444801_9582_4E12_9425_33567A600AF2__INCLUDED_)

#define AFX_DECODERRID_H__C9444801_9582_4E12_9425_33567A600AF2__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__

#error include 'stdafx. h' before including this file for PCH

#endif

#include "resource. h" // main symbols

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidApp:

// See Decoder Rid. cpp for the implementation of this class

//

Class CDecoderRidApp : public CWinApp

{

Public:

CDecoderRidApp();

// Overrides

// ClassWizard generated virtual function overrides

//[1]AFX_VIRTUAL

// Implementation

//[2]AFX_MSG

DECLARE_MESSAGE_MAP()

};

/////////////////////////////////////////////////////////////////////////////

//[3]

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DECODERRID_H__C9444801_9582_4E12_9425_33567A600AF2__INCLUDED_)

Файл RidDlg. h

// Decoder RidDlg. h : header file

//

#if! defined(AFX_DECODERRIDDLG_H__99108337_398F_43EE_8F95_D7AB96593444__INCLUDED_)

#define AFX_DECODERRIDDLG_H__99108337_398F_43EE_8F95_D7AB96593444__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidDlg dialog

Class CDecoderRidDlg : public CDialog

{

// Construction

Public:

CDecoderRidDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data

//[4]AFX_DATA

// ClassWizard generated virtual function overrides

//[5]AFX_VIRTUAL

// Implementation

Protected:

HICON m_hIcon;

// Generated message map functions

//[6]AFX_MSG

DECLARE_MESSAGE_MAP()

Private:

Int Majorit32(int sum);

Void DecrementR1();

Int Majorit16(int sum);

Void DecrementR2();

Int Majorit8(int sum);

Int mod2(int* m, int number);

Void DecrementR3();

Int Majorit4(int sum);

Void Init();

Int decordword[26];

Int codword[32];

};

//[3]

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DECODERRIDDLG_H__99108337_398F_43EE_8F95_D7AB96593444__INCLUDED_)

Файл Decoder Rid. cpp

// Decoder Rid. cpp : Defines the class behaviors for the application.

//

#include "stdafx. h"

#include "Decoder Rid. h"

#include "Decoder RidDlg. h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

Static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidApp

BEGIN_MESSAGE_MAP(CDecoderRidApp, CWinApp)

//[8]AFX_MSG

ON_COMMAND(ID_HELP, CWinApp::OnHelp)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidApp construction

CDecoderRidApp::CDecoderRidApp()

{

// TODO: add construction code here,

// Place all significant initialization in InitInstance

}

/////////////////////////////////////////////////////////////////////////////

// The one and only CDecoderRidApp object

CDecoderRidApp theApp;

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidApp initialization

BOOL CDecoderRidApp::InitInstance()

{

AfxEnableControlContainer();

// Standard initialization

// If you are not using these features and wish to reduce the size

// of your final executable, you should remove from the following

// the specific initialization routines you do not need.

#ifdef _AFXDLL

Enable3dControls(); // Call this when using MFC in a shared DLL

#else

Enable3dControlsStatic(); // Call this when linking to MFC statically

#endif

CDecoderRidDlg dlg;

M_pMainWnd = &dlg;

Int nResponse = dlg. DoModal();

If (nResponse == IDOK)

{

// TODO: Place code here to handle when the dialog is

// dismissed with OK

}

Else if (nResponse == IDCANCEL)

{

// TODO: Place code here to handle when the dialog is

// dismissed with Cancel

}

// Since the dialog has been closed, return FALSE so that we exit the

// application, rather than start the application's message pump.

Return FALSE;

}

/////////////////////////////////////////////////////////////////////////////

//[3]

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DECODERRID_H__C9444801_9582_4E12_9425_33567A600AF2__INCLUDED_)

Файл Decoder Rid. cpp

// Decoder RidDlg. cpp : implementation file

//

#include "stdafx. h"

#include "Decoder Rid. h"

#include "Decoder RidDlg. h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

Static char THIS_FILE[] = __FILE__;

#endif

Int G[26][32] =

{

{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},

{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},

{0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1},

{0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1},

{0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1},

{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}

};

Int H1[10][4][8] =

{

{

{0,1,2,3,4,5,6,7},

{8,9,10,11,12,13,14,15},

{16,17,18,19,20,21,22,23},

{24,25,26,27,28,29,30,31},

},

{

{0,1,2,3,8,9,10,11},

{4,5,6,7,12,13,14,15},

{16,17,18,19,24,25,26,27},

{20,21,22,23,28,29,30,31},

},

{

{0,1,4,5,8,9,12,13},

{2,3,6,7,10,11,14,15},

{16,17,20,21,24,25,28,29},

{18,19,22,23,26,27,30,31},

},

{

{0,2,4,6,8,10,12,14},

{1,3,5,7,9,11,13,15},

{16,18,20,22,24,26,28,30},

{17,19,21,23,25,27,29,31},

},

{

{0,1,2,3,16,17,18,19},

{4,5,6,7,20,21,22,23},

{8,9,10,11,24,25,26,27},

{12,13,14,15,28,29,30,31},

},

{

{2,3,6,7,18,19,22,23},

{0,1,4,5,16,17,20,21},

{8,9,12,13,24,25,28,29},

{10,11,14,15,26,27,30,31},

},

{

{0,2,4,6,16,18,20,22},

{1,3,5,7,17,19,21,23},

{8,10,12,14,24,26,28,30},

{9,11,13,15,25,27,29,31},

},

{

{0,1,8,9,16,17,24,25},

{2,3,10,11,18,19,26,27},

{4,5,12,13,20,21,28,29},

{6,7,14,15,22,23,30,31},

},

{

{0,2,8,10,16,18,24,26},

{1,3,9,11,17,19,25,27},

{4,6,12,14,20,22,28,30},

{5,7,13,15,21,23,29,31},

},

{

{0,4,8,12,16,20,24,28},

{1,5,9,13,17,21,25,29},

{2,6,10,14,18,22,26,30},

{3,7,11,15,19,23,27,31},

}

};

Int H2[10][8][4] =

{

{

{0,1,2,3},

{4,5,6,7},

{8,9,10,11},

{12,13,14,15},

{16,17,18,19},

{20,21,22,23},

{24,25,26,27},

{28,29,30,31}

},

{

{0,1,4,5},

{2,3,6,7},

{8,9,12,13},

{10,11,14,15},

{16,17,20,21},

{18,19,22,23},

{24,25,28,29},

{26,27,30,31}

},

{

{0,2,4,6},

{1,3,5,7},

{8,10,12,14},

{9,11,13,15},

{16,18,20,22},

{17,19,21,23},

{24,26,28,30},

{25,27,29,31},

},

{

{0,1,8,9},

{2,3,10,11},

{4,5,12,13},

{6,7,14,15},

{16,17,24,25},

{18,19,26,27},

{20,21,28,29},

{22,23,30,31},

},

{

{0,2,8,10},

{1,3,9,11},

{4,6,12,14},

{5,7,13,15},

{16,18,24,26},

{17,19,25,27},

{20,22,28,30},

{21,23,29,31},

},

{

{0,4,8,12},

{1,5,9,13},

{2,6,10,14},

{3,7,11,15},

{16,20,24,28},

{17,21,25,29},

{18,22,26,30},

{19,23,27,31},

},

{

{0,1,16,17},

{2,3,18,19},

{4,5,20,21},

{6,7,22,23},

{8,9,24,25},

{10,11,26,27},

{12,13,28,29},

{14,15,30,31},

},

{

{0,2,16,18},

{1,3,17,19},

{4,6,20,22},

{5,7,21,23},

{8,10,24,26},

{9,11,25,27},

{12,14,28,30},

{13,15,29,31},

},

{

{0,4,16,20},

{1,5,17,21},

{2,6,18,22},

{3,7,19,23},

{8,12,24,28},

{9,13,25,29},

{10,14,26,30},

{11,15,27,31},

},

{

{0,8,16,24},

{1,9,17,25},

{2,10,18,26},

{3,11,19,27},

{4,12,20,28},

{5,13,21,29},

{6,14,22,30},

{7,15,23,31},

}

};

Int H3[5][16][2]=

{

{

{0,1},

{2,3},

{4,5},

{6,7},

{8,9},

{10,11},

{12,13},

{14,15},

{16,17},

{18,19},

{20,21},

{22,23},

{24,25},

{26,27},

{28,29},

{30,31}

},

{

{0,2},

{1,3},

{4,6},

{5,7},

{8,10},

{9,11},

{12,14},

{13,15},

{16,18},

{17,19},

{20,22},

{21,23},

{24,26},

{25,27},

{28,30},

{29,31}

},

{

{0,4},

{1,5},

{2,6},

{3,7},

{8,12},

{9,13},

{10,14},

{11,15},

{16,20},

{17,21},

{18,22},

{19,23},

{24,28},

{25,29},

{26,30},

{27,31}

},

{

{0,8},

{1,9},

{2,10},

{3,11},

{4,12},

{5,13},

{6,14},

{7,15},

{16,24},

{17,25},

{18,26},

{19,27},

{20,28},

{21,29},

{22,30},

{23,31}

},

{

{0,16},

{1,17},

{2,18},

{3,19},

{4,20},

{5,21},

{6,22},

{7,23},

{8,24},

{9,25},

{10,26},

{11,27},

{12,28},

{13,29},

{14,30},

{15,31}

}

};

/////////////////////////////////////////////////////////////////////////////

// CAboutDlg dialog used for App About

Class CAboutDlg : public CDialog

{

Public:

CAboutDlg();

// Dialog Data

//[10]AFX_DATA

// ClassWizard generated virtual function overrides

//[11]AFX_VIRTUAL

// Implementation

Protected:

//[12]AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

//[13]AFX_DATA_INIT

}

Void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//[14]AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//[15]AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidDlg dialog

CDecoderRidDlg::CDecoderRidDlg(CWnd* pParent /*=NULL*/)

: CDialog(CDecoderRidDlg::IDD, pParent)

{

//[16]AFX_DATA_INIT

// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

M_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

Void CDecoderRidDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//[17]AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CDecoderRidDlg, CDialog)

//[18]AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CDecoderRidDlg message handlers

BOOL CDecoderRidDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX &; 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

If (pSysMenu!= NULL)

{

CString strAboutMenu;

StrAboutMenu. LoadString(IDS_ABOUTBOX);

If (!strAboutMenu. IsEmpty())

{

PSysMenu->AppendMenu(MF_SEPARATOR);

PSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}

}

// Set the icon for this dialog. The framework does this automatically

// when the application's main window is not a dialog

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIcon, FALSE); // Set small icon

Init();

Return TRUE; // return TRUE unless you set the focus to a control

}

Void CDecoderRidDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

If ((nID &; 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

DlgAbout. DoModal();

}

Else

{

CDialog::OnSysCommand(nID, lParam);

}

}

// If you add a minimize button to your dialog, you will need the code below

// to draw the icon. For MFC applications using the document/view model,

// this is automatically done for you by the framework.

Void CDecoderRidDlg::OnPaint()

{

If (IsIconic())

{

CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc. GetSafeHdc(), 0);

// Center icon in client rectangle

Int cxIcon = GetSystemMetrics(SM_CXICON);

Int cyIcon = GetSystemMetrics(SM_CYICON);

CRect rect;

GetClientRect(&;rect);

Int x = (rect. Width() - cxIcon + 1) / 2;

Int y = (rect. Height() - cyIcon + 1) / 2;

// Draw the icon

Dc. DrawIcon(x, y, m_hIcon);

}

Else

{

CDialog::OnPaint();

}

}

// The system calls this to obtain the cursor to display while the user drags

// the minimized window.

HCURSOR CDecoderRidDlg::OnQueryDragIcon()

{

Return (HCURSOR) m_hIcon;

}

Void CDecoderRidDlg::OnChangeCodeword()

{

UpdateData(TRUE);

For(int i = 0; i < m_codestring. GetLength(); i++)

If(m_codestring[i] != '1')

If(m_codestring[i] != '0')

{

Char bufer[100];

Sprintf(bufer, "%d-e neiaie aaaaai ia i?aaeeuii", i+1);

MessageBox(bufer);

M_codestring. Delete(i);

}

UpdateData(FALSE);

}

Void CDecoderRidDlg::OnDecoder()

{

Int i = 0;

Int k = 0;

If(m_codestring. GetLength() < 32)

{

MessageBox("Aaaaaiu ia ana neiaieu, iaaaaaaiiua neiaieu n?eoa?ony 0");

For(i = m_codestring. GetLength() - 1; i < 31; i++)

M_codestring += '0';

}

For(i = 0; i < 32; i++)

{

If(m_codestring[i] == '0')

Codword[i] = 0;

Else

Codword[i] = 1;

}

Int sum1[4] = {0,0,0,0};

For(i = 9, k = 0; i >= 0; i--, k++)

{

For(int j = 0; j < 4; j++)

{

Sum1[j] = codword[H1[k][j][0]] + codword[H1[k][j][1]] +

Codword[H1[k][j][2]] + codword[H1[k][j][3]] +

Codword[H1[k][j][4]] + codword[H1[k][j][5]] +

Codword[H1[k][j][6]] + codword[H1[k][j][7]];

Sum1[j] %= 2;

}

Decordword[16+i] = Majorit4(sum1[0]+sum1[1]+sum1[2]+sum1[3]);

}

DecrementR3();

Int sum2[8] = {0,0,0,0,0,0,0,0};

For(i = 9, k = 0; i >= 0; i--, k++)

{

For(int j = 0; j < 8; j++)

{

Sum2[j] = codword[H2[k][j][0]] + codword[H2[k][j][1]] +

Codword[H2[k][j][2]] + codword[H2[k][j][3]];

Sum2[j] %= 2;

}

Decordword[6+i] = Majorit8(sum2[0]+sum2[1]+sum2[2]+sum2[3]+

Sum2[4]+sum2[5]+sum2[6]+sum2[7]);

}

DecrementR2();

Int sum3[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

For(i = 5, k = 0; i >= 1; i--, k++)

{

For(int j = 0; j < 16; j++)

{

Sum3[j] = codword[H3[k][j][0]] + codword[H3[k][j][1]];

Sum3[j] %= 2;

}

Decordword[i] = Majorit16(sum3[0]+sum3[1]+sum3[2]+sum2[3]+sum3[4]+

Sum3[5]+sum3[6]+sum3[7]+sum3[8]+sum3[9]+

Sum3[10]+sum2[11]+sum3[12]+sum3[13]+

Sum3[14]+sum3[15]);

}

DecrementR1();

Int sum4 = 0;

For(i = 0; i < 32; i++)

Sum4 += codword[i];

Decordword[0] = Majorit32(sum4);

M_decodeword. Empty();

For(i = 0; i < 26; i++)

{

If(decordword[i] == 1)

M_decodeword += '1';

Else

M_decodeword += '0';

}

UpdateData(FALSE);

}

Void CDecoderRidDlg::Init()

{

Int r2[10][2] =

[19];

Int r3[10][3] =

[20];

For(int i = 6; i < 16; i++)

For(int j = 0; j < 32; j++)

G[i][j] = G[r2[i-6][0]][j]*G[r2[i-6][1]][j];

For(i = 16; i < 26; i++)

For(int j = 0; j < 32; j++)

G[i][j] = G[r3[i-16][0]][j]*G[r3[i-16][1]][j]*G[r3[i-16][2]][j];

}

Int CDecoderRidDlg::Majorit4(int sum)

{

If(sum <= 2)

Return 0;

Else

Return 1;

}

Void CDecoderRidDlg::DecrementR3()

{

Int v[11];

For(int i = 0; i < 32; i++)

{

V[0] = codword[i];

For(int j = 1; j < 11; j++)

V[j] = G[j+15][i]*decordword[j+15];

Codword[i] = mod2(v, 11);

}

}

Int CDecoderRidDlg::mod2(int *m, int number)

{

Int sum = 0;

For(int i =0; i < number; i++)

Sum += m[i];

Return sum % 2;

}

Int CDecoderRidDlg::Majorit8(int sum)

{

If(sum <= 4)

Return 0;

Else

Return 1;

}

Void CDecoderRidDlg::DecrementR2()

{

Int v[11];

For(int i = 0; i < 32; i++)

{

V[0] = codword[i];

For(int j = 1; j < 11; j++)

V[j] = G[j+5][i]*decordword[j+5];

Codword[i] = mod2(v, 11);

}

}

Int CDecoderRidDlg::Majorit16(int sum)

{

If(sum <= 8)

Return 0;

Else

Return 1;

}

Void CDecoderRidDlg::DecrementR1()

{

Int v[6];

For(int i = 0; i < 32; i++)

{

V[0] = codword[i];

For(int j = 1; j < 6; j++)

V[j] = G[j][i]*decordword[j];

Codword[i] = mod2(v, 6);

}

}

Int CDecoderRidDlg::Majorit32(int sum)

{

If(sum <= 16)

Return 0;

Else

Return 1;

}

    [1] AFX_VIRTUAL(CDecoderRidApp)

    Public:

    Virtual BOOL InitInstance();

    // [2] AFX_MSG(CDecoderRidApp)

    // NOTE - the ClassWizard will add and remove member functions here.

    // DO NOT EDIT what you see in these blocks of generated code!

    // [3] AFX_INSERT_LOCATION [4] AFX_DATA(CDecoderRidDlg)

    Enum { IDD = IDD_DECODERRID_DIALOG };

    CString m_codestring;

    CString m_decodeword;

    // [5] AFX_VIRTUAL(CDecoderRidDlg)

    Protected:

    Virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

    // [6] AFX_MSG(CDecoderRidDlg)

    Virtual BOOL OnInitDialog();

    Afx_msg void OnSysCommand(UINT nID, LPARAM lParam);

    Afx_msg void OnPaint();

    Afx_msg HCURSOR OnQueryDragIcon();

    Afx_msg void OnChangeCodeword();

    Afx_msg void OnDecoder();

    // [7] AFX_INSERT_LOCATION [8] AFX_MSG_MAP(CDecoderRidApp)

    // NOTE - the ClassWizard will add and remove mapping macros here.

    // DO NOT EDIT what you see in these blocks of generated code!

    // [9] AFX_INSERT_LOCATION [10] AFX_DATA(CAboutDlg)

    Enum { IDD = IDD_ABOUTBOX };

    // [11] AFX_VIRTUAL(CAboutDlg)

    Protected:

    Virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

    // [12] AFX_MSG(CAboutDlg)

    // [13] AFX_DATA_INIT(CAboutDlg)

    // [14] AFX_DATA_MAP(CAboutDlg)

    // [15] AFX_MSG_MAP(CAboutDlg)

    // No message handlers

    // [16] AFX_DATA_INIT(CDecoderRidDlg)

    M_codestring = _T("");

    M_decodeword = _T("");

    // [17] AFX_DATA_MAP(CDecoderRidDlg)

    DDX_Text(pDX, IDC_CODEWORD, m_codestring);

    DDV_MaxChars(pDX, m_codestring, 32);

    DDX_Text(pDX, IDC_DECODERWORD, m_decodeword);

    DDV_MaxChars(pDX, m_decodeword, 26);

    // [18] AFX_MSG_MAP(CDecoderRidDlg)

    ON_WM_SYSCOMMAND()

    ON_WM_PAINT()

    ON_WM_QUERYDRAGICON()

    ON_EN_CHANGE(IDC_CODEWORD, OnChangeCodeword)

    ON_BN_CLICKED(IDDECODER, OnDecoder)

    // [19] 1,2},

    {1,3},

    {1,4},

    {1,5},

    {2,3},

    {2,4},

    {2,5},

    {3,4},

    {3,5},

    {4,5 [20] 1,2,3},

    {1,2,4},

    {1,2,5},

    {1,3,4},

    {1,3,5},

    {1,4,5},

    {2,3,4},

    {2,3,5},

    {2,4,5},

    {3,4,5

Похожие статьи




Литература - Построение декодера Рида - Маллера

Предыдущая | Следующая