Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Practica-4 Longitud Promedio de Las Palabtras Codigo
Practica-4 Longitud Promedio de Las Palabtras Codigo
Profesor:
José Eduardo Guzmán Rodríguez
Grupo: 7CM21
27/03/2020
Objetivo.
El alumno identifica la diferencia entre la longitud de la palabra código y la longitud
promedio de la palabra código y calcula la eficiencia del código, realizando un
programa en MATLAB. El cual deberá mostrar una interfaz de usuario (GUI).
Consideración Generales.
Esta práctica se entrega en equipo con la investigación realizada impresa, con los
nombres de los integrantes del equipo, empezando por el apellido paterno. En
classroom se debe subir un archivo que contenga si es necesario el escaneo de los
cálculos realizados en el cuaderno, junto con una copia del programa realizado 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 tomara en cuenta para la calificación
del departamental. Es necesario que cada integrante suba la práctica a classroom
Antecedentes.
Una fuente de información puede que emita determinados símbolos a una tasa "r"
dada en símbolos/segundo. Entonces la tasa de información de la fuente será
calculada como sigue:
R= tasa de información, H=entropía de la fuente, r = tasa en cada símbolo generado.
R = r(símbolos/segundo) x H (bits de información/símbolo)
R=rH (bits de información/segundo)
Sea M un mensaje equiprobable tal que M=2N, si el mensaje es equiprobable, la
entropía H es máxima y está dada por:
Sea X un DMS con entropía finita H(X) y un alfabeto {XI, x2, , xm} con las
probabilidades de ocurrencia p(xi) donde i= 1,2,3,…m.
Sea una palabra código asignada a el símbolo Xi por el codificador de longitud ni
medido en bits. La longitud de la palabra código es el número de bits de la palabra
código.
La longitud promedio de la palabra código L está dada por:
El teorema de codificación fuente establece que para un DMS X con entropía H(s)
la longitud promedio de la palabra código por símbolo es delimitada como:
Ningún código puede lograr una eficiencia mayor que 1, pero para cualquier fuente,
hay códigos con eficiencia muy cerca al 1.
La fórmula no da un método para encontrar los mejores códigos. Simplemente
establece un límite de lo eficiente que puede ser.
Desarrollo.
1. Sea la siguiente imagen un DMS con 3
posibles de brillo codificado como se muestra
en la siguiente tabla.
A) ARCHIVO DE TEXTO
function varargout = texto(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input
arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises
the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to untitled_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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = texto_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)
%%%%%%%% TEXTO
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mensaje = get(hObject,'String');
handles.mensaje = mensaje;
guidata(hObject,handles);
%A = get(handles.edit1, 'string');
[archivo,ruta]=uigetfile({'*.txt;*UTF-8'}, 'Escoger')
A = fread(fid,10000000,'uint8=>char')'; %
%disp('El archivo de texto se carga')
%disp('Su contenido del archivo .txt es')
end
j=j+1;
k=k+1;
l=l+1;
m=m+1;
H=H+p*in;
end
end
simbolob = char(simbolo)
handles.simbolo =simbolo;
guidata(hObject,handles);
%datos = [cellstr(simbolob)' veces' ps' is];
% datos = [cellstr(simbolob)' num2cell(veces(:))' num2cell(ps(:))'
num2cell(is(:))']
datos = [cellstr(simbolob') num2cell(veces)' num2cell(ps)'
num2cell(is)'];
set(handles.uitable1,'data',datos)
set(handles.edit6,'String', H);
set(handles.edit7,'String',length(handles.mensaje));
%voy a hacer las variables globales
handles.simbolob= simbolob;
handles.veces=veces;
handles.ps=ps;
handles.is=is;
guidata(hObject,handles);
handles.H=H;
guidata(hObject,handles);
if(handles.j>2)
letra3 = char(handles.simbolo(3));
x = categorical({letra, letra2,letra3});
end
if(handles.j>3)
letra4 = char(handles.simbolo(4));
x = categorical({letra, letra2,letra3,letra4});
end
if(handles.j>4)
letra5 = char(handles.simbolo(5));
x = categorical({letra, letra2,letra3,letra4,letra5});
end
if(handles.j>5)
letra6 = char(handles.simbolo(6));
x = categorical({letra, letra2,letra3,letra4,letra5,letra6});
end
if(handles.j>6)
letra7 = char(handles.simbolo(7));
x = categorical({letra, letra2,letra3,letra4,letra5,letra6,letra7});
end
if (handles.j>7)
letra8 = char(handles.simbolo(8));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8});
end
if (handles.j>8)
letra9 = char(handles.simbolo(9));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8,letra9});
end
if (handles.j>9)
letra10 = char(handles.simbolo(10));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8,letra9,letra10});
end
if (handles.j>10)
letra11 = char(handles.simbolo(11));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8,letra9,letra10,letra11})
;
end
if(handles.j>1)
y = [handles.veces(1), handles.veces(2)];
end
if(handles.j>2)
y = [handles.veces(1), handles.veces(2), handles.veces(3)];
end
if(handles.j>3)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4)];
end
if(handles.j>4)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5)];
end
if(handles.j>5)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5), handles.veces(6)];
end
if(handles.j>6)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7)];
end
if(handles.j>7)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8)];
end
if(handles.j>8)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8),handles.veces(8)];
end
if(handles.j>9)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8),handles.veces(8),handles.veces(9)];
end
if(handles.j>10)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8),handles.veces(8),handles.veces(9),handles.veces(10)];
end
bar(x,y);
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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)
%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
binA = im2bw(handles.imagen);
handles.binA=binA;
guidata(hObject, handles)% salva los datos de la aplicación
imshow(binA)
title 'Imagen blanco y negro'; 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))) );
%calculo la probabilidad de 1 y 0
for x=1:9
for y = 1:11
if (handles.binA(x,y) == 1 )
P_x=P_x+1;
end
if (handles.binA(x,y) == 0 )
P_y=P_y+1;
end
end
end
prob1 = P_x/(P_x+P_y); %ps
prob2 = P_y/(P_x+P_y);
handles.prob1 = prob1;
handles.prob2 = prob2;
guidata(hObject,handles);
in1 = log2(1/prob1);
in2 = log2(1/prob2);
handles.in1 = in1;
handles.in2 = in2;
guidata(hObject,handles);
uno =1;
cero =0;
H=(in1+prob1)+(in2+prob2);
d= {1, P_x, prob1, in1 ; 0, P_y, prob2, in2 }
A= [1, P_x, prob1, in1 ];
B= [0, P_y, prob2, in2 ];
table = [A' B']
set(handles.uitable1,'data', d);
set(handles.edit5,'string',H);
handles.H=H;
guidata(hObject,handles);
handles.P_x=P_x;
guidata(hObject,handles);
handles.P_y=P_y;
guidata(hObject,handles);
handles.longitud = longitud;
guidata(hObject,handles);
set(handles.res_long, 'String',longitud);
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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)
%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
%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);
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);
Programa RGB
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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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)
%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
dimensiones = size(imagen)
set(handles.size, 'String', strcat(num2str(dimensiones(1)),' x ',
num2str(dimensiones(2)), ' x',num2str(dimensiones(3))) );
Red = handles.imagen;
handles.Red = Red;
guidata(hObject,handles);
Red(:,:,2) = 0; %RGB componente Rojo de la imagen original
%la entropia en cualquier capa es la misma
entropiared = entropy(handles.Red(:,:,2))
handles.entropiared = entropiared;
guidata(hObject,handles);
set(handles.edit7,'String',entropiared*3);
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = texto_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)
% BOTON
% --- Executes on button press in pushbutton1.
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)
%mensaje = fread(fid,10000000,'uint8=>char')
%A = get(handles.edit1, 'string');
A = fread(fid,10000000,'uint8=>char')'; %
%disp('El archivo de texto se carga')
%disp('Su contenido del archivo .txt es')
end
j=j+1;
k=k+1;
l=l+1;
m=m+1;
H=H+p*in;
end
end
simbolob = char(simbolo)
%datos = [cellstr(simbolob)' veces' ps' is];
% datos = [cellstr(simbolob)' num2cell(veces(:))' num2cell(ps(:))'
num2cell(is(:))']
datos = [cellstr(simbolob') num2cell(veces)' num2cell(ps)'
num2cell(is)'];
set(handles.uitable1,'data',datos)
set(handles.edit6,'String', H);
set(handles.edit7,'String',length(handles.mensaje));