转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
算术编码算法         ★★★★

算术编码算法

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1204 更新时间:2009/4/23 18:38:27
 

算术编码算法

  算术编码是把一个信源表示为实轴上0和1之间的一个区间,信源集合中的每一个元素都用来缩短这个区间。

   算术编码的过程如下:

(1)       设定编码区间的高段为h,编码区间的长度为g,EndC为编码字符分配的高段,StartC

为字符分配区间的低端。

(2)       根据有限的信源估算出各元素的概率。

(3)       杜宇编码的元素A1,根据(2)估算的概率和区间,计算出该元素编码后的新的l,和h。其公式如下:

         h = StartC + g* K;

         l = Endc + g* K1;

其具体程序如下:           

             

const  Ca = 0.2;  Ce = 0.3;

      Ci = 0.2;  Co = 0.2;

      Cu = 0.1;

var

  Form1: TForm1;

   s: string;

   StartC, EndC: Extended;

implementation

{$R *.dfm}

procedure ConvertTo(s: string; var StartC, EndC: Extended);{将字符串变为数值}

var n, i: integer;

    c: char;

    g: Extended;

begin

    StartC := 0;

    EndC := 1;

    n := Strlen(Pchar(s));

    for i := 1 to n do

    begin

       c := s[i];

       g := EndC - StartC;

       case C of

       ''''a'''':

         begin

            EndC :=StartC  + g * Ca;

            StartC := StartC + g * 0;

         end;

       ''''e'''':

          begin

            EndC := StartC + g * (Ca + Ce);

            StartC := StartC + g * Ca;

         end;

       ''''i'''':

          begin

            EndC := StartC + g * (Ca + Ce + Ci);

            StartC := StartC + g * (Ca + Ce);

         end;

       ''''o'''':

          begin

            EndC := StartC + g * (Ca + Ce + Ci + Co);

            StartC := StartC + g * (Ca + Ce + Ci);

         end;

       ''''u'''':

          begin

            EndC := StartC + g * (Ca + Ce + Ci + Co + Cu);

            StartC := StartC + g * (Ca + Ce + Ci + Co);

         end;

       else

           begin

            Showmessage('''' 输入的字符串有误 '''');

            exit;

           end;

      end;

    end;

end;

procedure NemuricalToStr(var s: String; var StartC, EndC: Extended);

{将数值转换为字符串}

const eps = -1e-5;

begin

  if StartC-0.2 < -eps  then

    if (EndC- 0.2<= -eps) and (EndC > StartC) then

    begin

       StartC := StartC / 0.2;

       EndC := EndC / 0.2;

       s := s + ''''a'''';

       if (StartC <>0) or (EndC <> 1) then

          NemuricaltoStr(s,StartC,EndC);

   end;

  if (StartC- 0.2 >= eps) and (StartC-0.5 < -eps) then

    if (EndC-0.5<= -eps) and (EndC>StartC) then

    begin

       StartC := StartC - 0.2;

       EndC := EndC - 0.2;

       StartC := StartC / 0.3;

       EndC := EndC / 0.3;

       s := s + ''''e'''';

       if (StartC <>0) or (EndC <> 1) then

          NemuricaltoStr(s,StartC,EndC);

  end ;

  if (StartC- 0.5>= eps) and (StartC- 0.7< -eps) then

    if (EndC-0.7<= -eps) and (EndC>StartC) then

    begin

       StartC := StartC - 0.5;

       EndC := EndC - 0.5;

       StartC := StartC / 0.2;

       EndC := EndC / 0.2;

       s := s + ''''i'''';

       if (StartC <>0) or (EndC <> 1) then

          NemuricaltoStr(s,StartC,EndC);

  end ;

  if (StartC-0.7 >= eps) and (StartC-0.9 < -eps) then

    if (EndC-0.9<=-eps) and (EndC>StartC) then

    begin

       StartC := StartC - 0.7;

       EndC := EndC - 0.7;

       StartC := StartC / 0.2;

       EndC := EndC / 0.2;

       s := s + ''''o'''';

       if (StartC <>0) or (EndC <> 1) then

          NemuricaltoStr(s,StartC,EndC);

  end ;

  if (StartC -0.9>=eps) and (StartC-1 < -eps) then

    if (EndC-1<= -eps) and (EndC>StartC) then

    begin

       StartC := StartC - 0.9;

       EndC := EndC - 0.9;

       StartC := StartC / 0.1;

       EndC := EndC / 0.1;

       s := s + ''''u'''';

       if (StartC <>0) or (EndC <> 1) then

     &nbs

[1] [2]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台