Está en la página 1de 27

Instituto Politécnico Nacional

Escuela Superior de Ingeniería


Mecánica y Eléctrica
Unidad Culhuacán

Teoría de la Información y Codificación


Practica 7
Representación de un canal en
MATLAB
Integrantes:
Báez Velázquez Alberto
Benítez Barrios Carlos Alberto
Cruz De la cruz Carlos Andrés

Profesor:
José Eduardo Guzmán Rodríguez

Grupo: 7CM21
04/05/2020
Objetivo:
El alumno conoce la representación de un canal simétrico binario de
comunicación por medio de matrices en Matlab.

CONSIDERACIONES GENERALES
Las practicas se entregan en una carpeta con el nombre de alguno de
los integrantes empezando por el apellido paterno, la carpeta debe
incluir en formato PDF o DOCX el reporte de la práctica, anexando
si es necesario el escaneo de los cálculos realizados en el cuaderno,
junto con el programa en MATLAB en la hora que corresponda al
laboratorio y en la fecha indicada, cualquier práctica recibida después
de la fecha no se tomará en cuenta para la calificación del
departamental. El día que se realiza la práctica se debe entregar un
programa funcional de manera individual (valor de 70%) y en la
próxima sesión se elige entre los integrantes el mejor programa y se
entrega ya terminado (valor 30%). Se tomará en cuenta para la
calificación del reporte: portada (O. I %), programa con GUI (20%),
desarrollo (.9%).

ANTECEDENTES
Un canal de comunicación puede ser definido, como la ruta o medio
a través del cual los símbolos fluyen para ser recibidos. Un canal
discreto sin memoria (DMC) es un modelo estadístico con una entrada
"X" y una salida "Y" como se muestra.
Durante cada intervalo de señalización, el canal acepta una señal de
entrada "X" y este responde generando una salida de símbolo.
El canal es discreto cuando el alfabeto tanto de "X" como de "Y" son
valores finitos.
Y es sin memoria cuando la salida actual únicamente depende de la
entrada actual y no de alguna entrada previa.
El diagrama de un DMC con entradas y “n” salidas se muestra a
continuación.

La entrada "X" consta de símbolos x , x2, La salida "Y" consta


de los símbolos yl, y2, yn. Cada posible ruta de entrada y salida es
indicada con una probabilidad condicional p(yj/xi) la cual indica la
probabilidad de tener una salida "y", dada la entrada "x" y es llamada
probabilidad de transición del canal.
Un canal es completamente especificado por el conjunto de
probabilidades de transición. Así un DMC usualmente se especifica
por una matriz de probabilidades de transición [P(y/x)].
La matriz [P(ylx)] es llamada matriz del canal, cada fila de la matriz
especifica las probabilidades de obtener yl, y2, yn dada XI. Así la
suma de los elementos en cualquier fila debe ser la unidad.

Si las probabilidades P(X) son representadas por las filas de la matriz,


entonces tenemos:

Las probabilidades de salida p(y) están representadas por las filas de


la matriz.

Las probabilidades de salida pueden ser representadas en términos de


las probabilidades de entrada.

Si [P(X)] es representada como una matriz diagonal.


Entonces [Pi(X,Y)] = [P(X)]d[P(Y|X)]
El elemento (i,j) de la matriz [P(X|Y)] tendrá la forma p(xi,yj).
La matriz [P(X,Y)] ES CONOCIDA COMO LA PROBABLILIDAD
ARTICULADA DE LA MATRIZ y el elemento p(xi,yj) es la
probabilidad de transmitir xi y recibir yj.

Un canal descrito por una matriz del canal con solo un elemento
distinto de cero en cada columna se llama un canal sin perdidas. En
un canal sin perdidas si ninguna información de origen se pierde en la
transmisión.

Un canal descrito por una matriz de canal con solo un elemento


distinto de cero en cada fila se llama un canal determinista.

Dado que cada fila tiene solo un elemento distinto de cero, este
elemento debe ser la unidad. Cuando se envía un símbolo de origen
dado a un canal determinista es evidente que el símbolo de salida se
recibe.
Un canal es llamado sin ruido si no perdidas y determinista. La matriz
del canal tiene solo un elemento en cada fila y en cada columna, y este
elemento es la unidad.
Los alfabetos de entrada y salida son del mismo tamaño.

CANAL BINARIO SIMETRICO


Un canal binario simétrico se define por el diagrama del canal que se
muestra a continuación y su matriz de canal está dada por:
La matriz de canal tiene 2 entradas O y 1, y 2 salidas 0 y 1.
Este canal es simétrico por que la probabilidad de recibir un 1 si un
0 se envía es la misma que la probabilidad de recibir un cero si un I
se envía.
Esta probabilidad común de transición está representada por la
probabilidad p.

Desarrollo

1. A partir de la matriz de canal binario.

A) Encuentra el diagrama del canal.


B) Encuentra p(y1) y p(y2) cuando p(x1) = p(x2) = 0.5.
C) Encuentra las probabilidades de articulación p(xq,y2) y
p(x2,y1) cuando p(x1) = p(x2) = 0.5.
• Nota: El punto anterior se realiza en tu cuaderno.
2.- Al programa de MATLAB utilizado en las anteriores practicas
agrega la capacidad de que pueda utilizar como entrada una secuencia
de bits (7 bits) provenientes de una imagen a escala de grises (no
utilices una imagen con demasiados bits), es probable que te sean de
utilidad las siguientes funciones:
"reshape ( )"
"rem ( )"
"berr"
"help bsc"
3.- El canal por el que se transmitirá la secuencia de bits será un canal
binario simétrico (BSC). Los bits que se envían a través del canal no
se deben enviar de una sola vez, estos se enviaran en grupos de 7 bits.
4.- Puedes utilizar la función "randerr ( )" para generar errores en la
transmisión.
5.- Agrupa los bits de salida en una sola secuencia (vector) después
compara los bits de entrada con los bits de salida y el programad debe
contar la cantidad de bits con errores.
6.- Pasa el vector de salida a una matriz con dimensiones iguales a la
matriz de la imagen de entrada. Por último compara las imágenes de
entrada y salida, y comenta que efectos observas en la imagen de
salida.

*NOTA 2: Se tomará como Ipunto extra en la calificación de examen


si al programa de Matlab agregas el código de Huffman dinámico y
adaptativo.
Programa de Matlab Representación de un canal

Probando con un pixel gris de la imagen (p = 0.33 1 bit errado)


Probando con un bit blanco de la imagen(p=0.9 bits errados 6)

Probando con un bit blanco de la imagen(p=0.36 bits errados 3)

Probando con un vector de entrada llamado random(p= 0.47 4


Bits errados )
Código de Matlab

function varargout = archivo1(varargin)


% ARCHIVO1 MATLAB code for archivo1.fig
% ARCHIVO1, by itself, creates a new ARCHIVO1 or raises the existing
% singleton*.
%
% H = ARCHIVO1 returns the handle to a new ARCHIVO1 or the handle to
% the existing singleton*.
%
% ARCHIVO1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ARCHIVO1.M with the given input
arguments.
%
% ARCHIVO1('Property','Value',...) creates a new ARCHIVO1 or raises
the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before archivo1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to archivo1_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 archivo1

% Last Modified by GUIDE v2.5 04-May-2020 15:56:36

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @archivo1_OpeningFcn, ...
'gui_OutputFcn', @archivo1_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 archivo1 is made visible.
function archivo1_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 archivo1 (see VARARGIN)

% Choose default command line output for archivo1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes archivo1 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = archivo1_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;

% --- Executes on button press in pushbutton1. "BOOOOOOOTON 1"


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName, Path] = uigetfile({'*.jpg,*.bmp'},'Abrir Imagen');
if isequal(FileName,0) %evalua si una matriz (A,B) son iguales para ver
si esta vacia y retornar la funcion
return
else %si la matriz no esta vacia entonces carga esa imagen
%imread carga la imagen FileName del directorio Path
%Strcat uno concatena varios string str = string, cat =concatena
imagen = imread(strcat(Path, FileName));
axes(handles.imagen);
imshow(imagen);
title 'Imagen RGB CARGADA'; xlabel 'eje x'; ylabel 'eje y';

%B imagen = imread('imagen.jpg'); %B
end
%handles es identificador de datos de la aplicación, almacena %id_global
handles.imagen=imagen; %B
guidata(hObject, handles)% A Y B salva los datos de la aplicación
% Hint: get(hObject,'Value') returns toggle state of pushbutton1

% --- Executes on button press in pushbutton2. "BOOOOOOTON 2"


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
binA = rgb2gray(handles.imagen);%convertimos a escala de grises
handles.binA=binA;
guidata(hObject, handles)% salva los datos de la aplicación
imshow(binA)
title 'Imagen ESC GRISES '; xlabel 'eje x'; ylabel 'eje y';
disp('A continuación mostraremos la matriz de valores binarios de B/N');
dimensiones = size(binA)
set(handles.size, 'String', strcat(num2str(dimensiones(1)),' x ',
num2str(dimensiones(2))) );

function size_Callback(hObject, eventdata, handles)


% hObject handle to size (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 size as text


% str2double(get(hObject,'String')) returns contents of size as a
double

% --- Executes during object creation, after setting all properties.


function size_CreateFcn(hObject, eventdata, handles)
% hObject handle to size (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

function pixel_x_Callback(hObject, eventdata, handles)


% hObject handle to pixel_x (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 pixel_x as text


% str2double(get(hObject,'String')) returns contents of pixel_x as
a double
pixel_x = str2num(get (hObject, 'String' ))
handles.pixel_x = pixel_x;
guidata(hObject, handles);
pixel_x

% --- Executes during object creation, after setting all properties.


function pixel_x_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_x (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

function pixel_y_Callback(hObject, eventdata, handles)


% hObject handle to pixel_y (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 pixel_y as text


% str2double(get(hObject,'String')) returns contents of pixel_y as
a double
pixel_y = str2num (get (hObject, 'String' ))
handles.pixel_y = pixel_y;
guidata(hObject, handles);
pixel_y

% --- Executes during object creation, after setting all properties.


function pixel_y_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_y (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 valor.


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

% --- Executes during object creation, after setting all properties.


function valor_CreateFcn(hObject, eventdata, handles)
% hObject handle to valor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
res = num2str(handles.binA(handles.pixel_x, handles.pixel_y));
num_res = str2num(res);
res_bin = (dec2bin(num_res));
set(handles.valor, 'String' , (res_bin));

% --- Executes on selection change in listbox1.


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

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1


contents as cell array
% contents{get(hObject,'Value')} returns selected item from
listbox1

% --- Executes during object creation, after setting all properties.


function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: listbox 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

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a
double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
entropia = entropy(handles.binA);
set(handles.edit5,'String',entropia);
handles.entropia= entropia;
guidata(hObject,handles);

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%OBTENCIÓN DE LAS DIMENSIONES PARA IMPRIMIRLAS EN PANTALLA
imagen_gris = handles.binA;
SZ = size(imagen_gris);
handles.SZ=SZ;
guidata(hObject,handles);

%USO LAS DIMENSIONES PARA MULTIPLICARLAS Y OBTENER NÚMERO DE MUESTRAS


muestras = SZ(1)*SZ(2);
handles.muestras = muestras;
guidata(hObject, handles);
set(handles.edit6,'String',muestras);

% Obtener el rango de los datos


valMin = min(min(imagen_gris(:,:)));
valMax = max(max(imagen_gris(:,:)));
handles.valMin = valMin;
guidata(hObject, handles);
handles.valMax = valMax;
guidata(hObject, handles);
Rango = valMax - valMin;
handles.Rango = Rango;

%calculos de frecuencia non-existent field 'pixy

%var_y = handles.pixel_y
blanco =0; gris = 0; negro =0;
for i = 1:SZ(1)
for y = 1:SZ(2)
if(imagen_gris(i,y) == 0)
negro=negro+1;
end
if(imagen_gris(i,y) == 127)
gris=gris+1;
end
if(imagen_gris(i,y) == 255)
blanco=blanco+1;
end

end
end
set(handles.edit7,'String',blanco);
set(handles.edit8,'String',gris);
set(handles.edit9,'String',negro);

%calculamos intervalos a utilizar


k = round(1+3.3*log(muestras));

%cantidad de datos potencialmente a incluir en cada inter. de clase

A= round(Rango/k)

%grafica de barras
c = categorical({'Negro','Gris','Blanco'});
%x = [255,127,0];
y = [negro, gris, blanco];
axes(handles.axes3);
bar(c,y);
handles.blanco = blanco;
handles.negro = negro;
handles.gris = gris;
guidata(hObject,handles);

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a
double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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

function edit8_Callback(hObject, eventdata, handles)


% hObject handle to edit8 (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 edit8 as text


% str2double(get(hObject,'String')) returns contents of edit8 as a
double

% --- Executes during object creation, after setting all properties.


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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

function edit9_Callback(hObject, eventdata, handles)


% hObject handle to edit9 (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 edit9 as text


% str2double(get(hObject,'String')) returns contents of edit9 as a
double

% --- Executes during object creation, after setting all properties.


function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (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 longitud.


%longitud promedio de coódigo
function longitud_Callback(hObject, eventdata, handles)
longitud = (4)*(handles.negro/handles.muestras)
+(2)*(handles.gris/handles.muestras)+(handles.blanco/handles.muestras);
set(handles.res_longitud,'String',longitud);
handles.longitud = longitud;
guidata(hObject,handles);
function res_longitud_Callback(hObject, eventdata, handles)
% hObject handle to res_longitud (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 res_longitud as text


% str2double(get(hObject,'String')) returns contents of
res_longitud as a double

% --- Executes during object creation, after setting all properties.


function res_longitud_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_longitud (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 eficiencia.


%EFICIENCIA
function eficiencia_Callback(hObject, eventdata, handles)
eficiencia = handles.entropia/ handles.longitud;
set(handles.res_eficiencia, 'String', eficiencia);
handles.eficiencia = eficiencia;
guidata(hObject, handles);

function res_eficiencia_Callback(hObject, eventdata, handles)


% hObject handle to res_eficiencia (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 res_eficiencia as text


% str2double(get(hObject,'String')) returns contents of
res_eficiencia as a double

% --- Executes during object creation, after setting all properties.


function res_eficiencia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_eficiencia (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 redundancia.


function redundancia_Callback(hObject, eventdata, handles)
redundancia = 1-handles.eficiencia;
set(handles.res_redundancia, 'String',redundancia);

function res_redundancia_Callback(hObject, eventdata, handles)


% hObject handle to res_redundancia (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 res_redundancia as


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

% --- Executes during object creation, after setting all properties.


function res_redundancia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_redundancia (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

%VALOR DEL SLIDER P


function valor_p_Callback(hObject, eventdata, handles)
valor_p = get(handles.valor_p, 'Value');
set(handles.p, 'String',valor_p);
handles.valorp = valor_p
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function valor_p_CreateFcn(hObject, eventdata, handles)
% hObject handle to valor_p (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

function vector_entrada_Callback(hObject, eventdata, handles)


% hObject handle to vector_entrada (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 vector_entrada as text


% str2double(get(hObject,'String')) returns contents of
vector_entrada as a double

% --- Executes during object creation, after setting all properties.


function vector_entrada_CreateFcn(hObject, eventdata, handles)
% hObject handle to vector_entrada (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

function vector_salida_Callback(hObject, eventdata, handles)


% hObject handle to vector_salida (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 vector_salida as text


% str2double(get(hObject,'String')) returns contents of
vector_salida as a double

% --- Executes during object creation, after setting all properties.


function vector_salida_CreateFcn(hObject, eventdata, handles)
% hObject handle to vector_salida (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

% --- CANAL BSC


function pushbutton9_Callback(hObject, eventdata, handles)
if(handles.valor_popmenu_valop_entrada == 1)

z = ((randi ([0 1], 1,7))); % Matriz aleatoria

elseif (handles.valor_popmenu_valop_entrada == 2)
z = [1 1 1 1 1 1 1];

elseif (handles.valor_popmenu_valop_entrada == 3)
z = [0 0 0 0 0 0 0]

elseif(handles.valor_popmenu_valop_entrada == 4)
%j_num = (handles.binA(handles.pixel_x, handles.pixel_y)) %
Matriz aleatoria
%j = dec2bin(j_num)
% z = [str2num(j(1)), str2num(j(2)), str2num(j(3)), str2num(j(4)),
str2num(j(5)), str2num(j(6)), str2num(j(7))]

end

canal_bsc = bsc(z, handles.valorp)% Canal simétrico binario


[error, caracteres] = biterr (z, canal_bsc) % Número y porcentaje de
errores

set(handles.vector_entrada, 'String', mat2str(z));


set(handles.vector_salida, 'String', mat2str(canal_bsc));
set(handles.bits_erroneos, 'String', error);

function edit17_Callback(hObject, eventdata, handles)


% hObject handle to edit17 (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 edit17 as text


% str2double(get(hObject,'String')) returns contents of edit17 as
a double

% --- Executes during object creation, after setting all properties.


function edit17_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit17 (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

%valor p
function p_Callback(hObject, eventdata, handles)
set(handles.p, 'String',valor_p);
% --- Executes during object creation, after setting all properties.
function p_CreateFcn(hObject, eventdata, handles)
% hObject handle to p (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 selection change in popmenu_vector_entrada.


function popmenu_vector_entrada_Callback(hObject, eventdata, handles)
valor_popmenu_valop_entrada = get(handles. popmenu_vector_entrada,
'Value');
handles.valor_popmenu_valop_entrada = valor_popmenu_valop_entrada;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.


function popmenu_vector_entrada_CreateFcn(hObject, eventdata, handles)
% hObject handle to popmenu_vector_entrada (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: popupmenu 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

function bits_erroneos_Callback(hObject, eventdata, handles)


% hObject handle to bits_erroneos (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 bits_erroneos as text


% str2double(get(hObject,'String')) returns contents of
bits_erroneos as a double

% --- Executes during object creation, after setting all properties.


function bits_erroneos_CreateFcn(hObject, eventdata, handles)
% hObject handle to bits_erroneos (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

También podría gustarte