【游戏】基于matlab GUI循环码编译码器【含Matlab源码 692期】

一、简介

1 循环码的概念
循环性是指任意码组循环移位后仍然是该编码中的一个码组
多项式表示法
一般情况
在这里插入图片描述
在这里插入图片描述
2 循环码的运算
2.1 整数的按模运算
在这里插入图片描述
2.2 码多项式的按模运算
在这里插入图片描述
2.3 循环码的数学表示法
在这里插入图片描述
2.4 循环码的生成
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2.5 寻求码生成多项式
在这里插入图片描述
在这里插入图片描述
2.3 循环码的编码方法
在这里插入图片描述
在这里插入图片描述
2.4 循环码的解码方法
在这里插入图片描述

二、源代码

function varargout = xinxilun(varargin)
% XINXILUN MATLAB code for xinxilun.fig
%      XINXILUN, by itself, creates a new XINXILUN or raises the existing
%      singleton*.
%
%      H = XINXILUN returns the handle to a new XINXILUN or the handle to
%      the existing singleton*.
%
%      XINXILUN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in XINXILUN.M with the given input arguments.
%
%      XINXILUN('Property','Value',...) creates a new XINXILUN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before xinxilun_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to xinxilun_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help xinxilun

% Last Modified by GUIDE v2.5 04-Dec-2013 16:15:30

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @xinxilun_OpeningFcn, ...
                   'gui_OutputFcn',  @xinxilun_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{
    
    1})
    gui_State.gui_Callback = str2func(varargin{
    
    1});
end

if nargout
    [varargout{
    
    1:nargout}] = gui_mainfcn(gui_State, varargin{
    
    :});
else
    gui_mainfcn(gui_State, varargin{
    
    :});
end
% End initialization code - DO NOT EDIT


% --- Executes just before xinxilun is made visible.
function xinxilun_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to xinxilun (see VARARGIN)

% Choose default command line output for xinxilun
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
axes(handles.axes1);
axis off;
axes(handles.axes2);
axis off;

% UIWAIT makes xinxilun wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = xinxilun_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{
    
    1} = handles.output;



function m_in_Callback(hObject, eventdata, handles)
% hObject    handle to m_in (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of m_in as text
%        str2double(get(hObject,'String')) returns contents of m_in as a double


% --- Executes during object creation, after setting all properties.
function m_in_CreateFcn(hObject, eventdata, handles)
% hObject    handle to m_in (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in bm_pushbutton.
function bm_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to bm_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global c;
mm=get(handles.m_in,'string');
if length(mm)~=4
    errordlg('信息码字长度只能是4位!','非法输入!'); 
elseif length(mm)==4
    for i=1:4
        m(i)=str2num(mm(i));                               %判断输入是否合法
    end
    if ((m(1)~=0&&m(1)~=1)||(m(2)~=0&&m(2)~=1)||(m(3)~=0&&m(3)~=1)||(m(4)~=0&&m(4)~=1))
        errordlg('只能输入0或1!','非法输入!');
    else
        set(handles.jspanel,'visible','on');
        c=coding(m);              %调用函数编码
        cc=num2str(c(1,1:7));
        set(handles.text3,'visible','on');
        set(handles.m_out_text,'string',cc);             %画图
        axes(handles.axes1);
        stairs(0:7,c,'linewidth',2);
        axis([0,7,0,1]);
        set(gca,'XTick',0:1:7);
        set(gca,'YTick',[]);
        grid on;
    end
end



function e_edit_Callback(hObject, eventdata, handles)
% hObject    handle to e_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of e_edit as text
%        str2double(get(hObject,'String')) returns contents of e_edit as a double


% --- Executes during object creation, after setting all properties.
function e_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to e_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in e_button.
function e_button_Callback(hObject, eventdata, handles)
% hObject    handle to e_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
out =randi([0 7],1);
e=zeros(1,7);
if out~=0
    e(out)=1;
end
for i=1:7
    ee(i)=num2str(e(i)); %转化为字符串
end  
set(handles.e_edit,'string',ee);


% --- Executes on button press in dj_button.
function dj_button_Callback(hObject, eventdata, handles)
% hObject    handle to dj_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global r;
global c;
ee=get(handles.e_edit,'string');
if length(ee)~=7
    errordlg('错误图样长度是7位!','非法输入!'); 
elseif length(ee)==7
    for i=1:7
        e(i)=str2num(ee(i));
    end
    if ((e(1)~=0&&e(1)~=1)||(e(2)~=0&&e(2)~=1)||(e(3)~=0&&e(3)~=1)||(e(4)~=0&&e(4)~=1)||(e(5)~=0&&e(5)~=1)||(e(6)~=0&&e(6)~=1)||(e(7)~=0&&e(7)~=1))
        errordlg('只能输入0或1!','非法输入!');
    elseif sum(e)>1
        errordlg('超出纠错范围,只能纠1位错,请重新输入!','非法输入!');    
    else
        set(handles.uipanel3,'visible','on');
        r=xor(c(1,1:7),e);
        rr=num2str(r);
        set(handles.text7,'visible','on');
        set(handles.r_text,'string',rr);             %画图
        axes(handles.axes2);
        stairs(0:7,[r,r(7)],'linewidth',2);
        axis([0,7,0,1]);
        set(gca,'XTick',0:1:7);
        set(gca,'YTick',[]);
        grid on;
    end
end

三、运行结果

在这里插入图片描述

四、备注

完整代码或者代写添加QQ 1564658423

猜你喜欢

转载自blog.csdn.net/TIQCmatlab/article/details/115434435