AdaptShrink2.m
上传用户:sla11nk8
上传日期:2013-03-09
资源大小:21k
文件大小:4k
源码类别:

其他

开发平台:

Matlab

  1. function out=AdaptShrink2(wcY,L)
  2. %
  3. %%%%It's My Own Function!!!!!
  4. %
  5. %%%% out=AdaptShrink(wcY,L)
  6. [n,J] = dyadlength(wcY);
  7. ws=wcY;
  8. for j=(J-1):-1:L
  9.  for kk=1:3%对3个方向的系数分别处理
  10.      switch kk
  11.         case 1
  12.             %得到当前矩阵
  13.             [t1,t2]=dyad2LH(j);
  14.             wcCorrent=wcY(t1,t2);
  15.             if j~=L
  16.             %得到其父结点矩阵
  17.                [p1,p2]=dyad2LH(j-1);
  18.                wcParent=wcY(p1,p2);
  19.             end;
  20.             
  21.         case 2
  22.             %得到当前矩阵
  23.             [t1,t2]=dyad2HL(j);
  24.             wcCorrent=wcY(t1,t2);
  25.             if j~=L
  26.             %得到其父结点矩阵
  27.                [p1,p2]=dyad2HL(j-1);
  28.                wcParent=wcY(p1,p2);
  29.             end;
  30.         case 3
  31.             %得到当前矩阵
  32.             [t1,t2]=dyad2HH(j);
  33.             wcCorrent=wcY(t1,t2);
  34.             if j~=L
  35.             %得到其父结点矩阵
  36.                [p1,p2]=dyad2HH(j-1);
  37.                wcParent=wcY(p1,p2);
  38.             end;
  39.             
  40.        end;
  41.          
  42.     
  43.      %求出z(k1,k2)
  44.      z=abs(wcCorrent);
  45.      nn=2^j;
  46.      for k1=2:(nn-1)
  47.          for k2=2:(nn-1)
  48.              %求向量u
  49.              u(1)=wcCorrent(k1-1,k2-1);
  50.              u(2)=wcCorrent(k1,k2-1);
  51.              u(3)=wcCorrent(k1+1,k2-1);
  52.              u(4)=wcCorrent(k1+1,k2);
  53.              u(5)=wcCorrent(k1+1,k2+1);
  54.              u(6)=wcCorrent(k1,k2+1);
  55.              u(7)=wcCorrent(k1-1,k2+1);
  56.              u(8)=wcCorrent(k1-1,k2);
  57.              u(9)=wcCorrent(k1,k2);
  58.              if (j==L)
  59.                  u(10)=u(9);
  60.              else
  61.                  u(10)=wcParent(round(k1/2),round(k2/2));
  62.              end;
  63.              %求向量w
  64.              %w=ones(1,10)/10;
  65.              w=[1 1 1 1 1 1 1 1 0 1]./9;
  66.              z(k1,k2)=sum(w.*abs(u));%求出z(k1,k2)
  67.          end;
  68.      end;
  69.         
  70.      %对z矩阵的元素排序
  71.      z_1d=[];
  72.      for k1=1:nn
  73.          z_1d=[z_1d z(k1,:)];
  74.      end;
  75.      [zOrder,index]=sort(z_1d);
  76.      %计算窗口大小LL
  77.      LL=max(50,floor(0.02*nn*nn));
  78.      
  79.      [k1,k2]=MapTo2d(index,nn);%1维向量的标号映射到2维标号
  80.      
  81.      z=wcCorrent;
  82.      for p=1:nn*nn
  83.          %计算实际窗口大小
  84.          begin=max(p-LL,1);
  85.          eend=min(p+LL,nn*nn);
  86.          total=eend-begin+1;
  87.               
  88.       if (p==1)
  89.              sumY2=0;
  90.              for t=1:(LL+1)
  91.                  sumY2=sumY2+wcCorrent(k1(t),k2(t))^2;
  92.              end;
  93.          elseif (p-LL)<2%窗口左侧数据不够
  94.                  sumY2=sumY2+wcCorrent(k1(p+LL),k2(p+LL))^2;
  95.              elseif (p+LL)>nn*nn%窗口右侧数据不够
  96.                      tempp=wcCorrent(k1(p-LL-1),k2(p-LL-1))^2;
  97.                      sumY2=sumY2-tempp;
  98.                  else%窗口数据足够
  99.                      tempp=wcCorrent(k1(p-LL-1),k2(p-LL-1))^2;
  100.                      sumY2=sumY2-tempp;
  101.                      tempp=wcCorrent(k1(p+LL),k2(p+LL))^2;
  102.                      sumY2=sumY2+tempp;
  103.          end;
  104.       
  105.         %噪声方差归一化
  106.          sigma=1;
  107.          sitaX2=sumY2/total-sigma^2;
  108.          if (sitaX2<0)%噪声太大
  109.              z(k1(p),k2(p))=0;
  110.          else
  111.              thresh=sigma^2/sqrt(sitaX2);
  112.              z(k1(p),k2(p))=SoftThresh(wcCorrent(k1(p),k2(p)),thresh);
  113.          end;
  114.      end;
  115.      ws(t1,t2)=z;
  116.  end;
  117. end;
  118. out=ws;      
  119.      
  120.      function [k1,k2]=MapTo2d(k,n)
  121.      %1维向量的标号映射到2维标号
  122.      k1=ceil(k./n);
  123.      k2=k-(k1-1).*n;
  124.      
  125.                  
  126.                  
  127.                  
  128.                  
  129.                  
  130.                  
  131.                  
  132.