声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

楼主: simon21

[小波] [分享]个人收集的一些关于小波分析的matlab程序

 关闭 [复制链接]
 楼主| 发表于 2007-4-4 07:18 | 显示全部楼层

二维小波变换(正和逆变换)

二维小波变换(正和逆变换),用二维卷积实现的,其中有个子函数用于产生小波系数的(小波分解和小波重构的系数都有)!你自己也可以往里面加系数!

  1. function [varargout]=wavefilter(wname,type)
  2. error(nargchk(1,2,nargin));
  3. if(nargin==1 & nargout ~=4) | (nargin==2 & nargout~=2)
  4.     error('Invalid number of output arguments.');
  5. end
  6. if nargin==1 & ~ischar(wname)
  7.     error('WNAME must be a string.');
  8. end
  9. if nargin==2 & ~ischar(type)
  10.     error('TYPE must be a string.');
  11. end

  12. switch lower(wname)
  13.     case {'haar','db1'}
  14.         ld=[1 1]/sqrt(2); hd=[-1 1]/sqrt(2);
  15.         lr=ld;            hr=-hd;
  16.     case 'db4'
  17.         ld=[-1.059740178499728e-002 3.288301166698295e-002 3.084138183598697e-002 -1.870348117188811e-001 ...
  18.             -2.798376941698385e-002 6.308807679295904e-001 7.148465705525415e-001 2.303778133088552e-001];
  19.         t=[0:7];
  20.         hd=ld; hd(end:-1:1)=cos(pi*t).*ld;
  21.         lr=ld; lr(end:-1:1)=ld;
  22.         hr=cos(pi*t).*ld;
  23.         
  24.     case 'sym4'
  25.         ld=[-7.576571478927333e-002 -2.963552764599851e-002 4.976186676320155e-001 8.037387518059161e-001 ...
  26.             2.978577956052774e-001  -9.921954357684722e-002 -1.260396726203783e-002 3.222310060404270e-002];
  27.         t=[0:7];
  28.         hd=ld; hd(end:-1:1)=cos(pi*t).*ld;
  29.         lr=ld; lr(end:-1:1)=ld;
  30.         hr=cos(pi*t).*ld;
  31.     case 'bior6.8'
  32.         ld=[0 1.908831736481291e-003 -1.9142861290088767e-003 -1.699063986760234e-002 1.1934565279772926e-002 ...
  33.             4.973290349094079e-002 -7.726317316720414e-002 -9.405920349573646e-002 4.207962846098268e-001 ...
  34.             8.259229974584023e-001 4.207962846098268e-001 -9.405920349573646e-002 -7.726317316720414e-002 ...
  35.             4.973290349094079e-002 1.193456527972926e-002 -1.699063986760234e-002 -1.914286129088767e-003 ...
  36.             1.908831736481291e-003];
  37.         hd=[0 0 0 1.442628250562444e-002 -1.446750489679015e-002 -7.872200106262882e-002 4.036797903033992e-002 ...
  38.             4.178491091502746e-001 -7.589077294536542e-001 4.178491091502746e-001 4.036797903033992e-002 ...
  39.             -7.872200106262882e-002 -1.446750489679015e-002 1.442628250562444e-002 0 0 0 0];
  40.         t=[0:17];
  41.         lr=cos(pi*(t+1)).*hd;
  42.         hr=cos(pi*t).*ld;
  43.         
  44.     case 'jpeg9.7'
  45.         ld=[0 0.02674875741080976 -0.01686411844287495 -0.07822326652898785 0.2668641184428723 ...
  46.             0.6029490182363579 0.2668641184428723 -0.07822326652898785 -0.01686411844287495  ...
  47.             0.02674875741080976];
  48.         hd=[0 -0.09127176311424948 0.05754352622849957 0.5912717631142470 -1.115087052456994 ...
  49.             0.5912717631142470 0.05754352622849957 -0.09127176311424948 0 0];
  50.         t=[0:9];
  51.         lr=cos(pi*(t+1)).*hd;
  52.         hr=cos(pi*t).*ld;
  53.     otherwise
  54.         error('Unrecongizable wavelet name (WNAME).');
  55. end
  56. if(nargin==1)
  57.     varargout(1:4)={ld,hd,lr,hr};
  58. else
  59.     switch lower(type(1))
  60.         case 'd'
  61.             varargout={ld,hd};
  62.         case 'r'
  63.             varargout={lr,hr};
  64.         otherwise
  65.             error('Unrecongizable filter TYPE.');
  66.     end
  67. end
复制代码

  1. function [c,s]=wavefast(x,n,varargin)
  2. error(nargchk(3,4,nargin));
  3. if nargin==3
  4.     if ischar(varargin{1})
  5.         [lp,hp]=wavefilter(varargin{1},'d');
  6.     else
  7.         error('Missing wavelet name.');
  8.     end
  9. else
  10.     lp=varargin{1}; hp=varargin{2};
  11. end
  12. fl=length(lp);sx=size(x);
  13. if (ndims(x)~=2) | (min(sx)<2) | ~isreal(x) | ~isnumeric(x)
  14.     error('X must be a real ,numeric matric.');
  15. end
  16. if(ndims(lp)~=2) | ~ isreal(lp) | ~isnumeric(lp) | (ndims(hp) ~=2) | ~ isreal(hp) | ~isnumeric(hp) ...
  17.         | (fl~=length(hp)) | rem(fl,2)~=0
  18.     error(['LP and HP must be ever and equal length real numeric filter vector.']);
  19. end
  20. if ~isreal(n) | ~isnumeric(n) |(n<1) |(n>log2(max(sx)))
  21.     error(['N must be a real scalar between 1 and log2(max(size(X))).']);
  22. end
  23. c=[];s=sx;app=double(x);
  24. for i=1:n
  25.     [app,keep]=symextend(app,fl);
  26.     rows=symconv(app,hp,'row',fl,keep);
  27.     coefs=symconv(rows,hp,'col',fl,keep);
  28.     c=[coefs(:)' c]; s=[size(coefs);s];
  29.     coefs=symconv(rows,lp,'col',fl,keep);
  30.     c=[coefs(:)' c];
  31.     rows=symconv(app,lp,'row',fl,keep);
  32.     coefs=symconv(rows,hp,'col',fl,keep);
  33.     c=[coefs(:)' c];
  34.     app=symconv(rows,lp,'col',fl,keep);
  35. end
  36. c=[app(:)' c]; s=[size(app);s];
  37. function [y, keep]=symextend(x,fl)
  38. keep=floor((fl+size(x)-1)/2);
  39. y=padarray(x,[(fl-1) (fl-1)],'symmetric','both');
  40. function y=symconv(x,h,type,fl,keep)
  41. if strcmp(type, 'row')
  42.     y=conv2(x,h);
  43.     y=y(:,1:2:end);
  44.     y=y(:,fl/2+1:fl/2+keep(2));
  45. else
  46.     y=conv2(x,h');
  47.     y=y(1:2:end,:);
  48.     y=y(fl/2+1:fl/2+keep(2),:);
  49. end
复制代码

  1. function [varargout]=waveback(c,s,varargin)
  2. error(nargchk(3,5,nargin));
  3. error(nargchk(1,2,nargout));
  4. if(ndims(c) ~=2) | (size(c,1) ~=1)
  5.     error('C must be a row vector .');
  6. end
  7. if (ndims(s) ~=2) | ~isreal(s) | ~isnumeric(s) | (size(s,2) ~=2)
  8.     error('S must be a real,numeric two-column array.');
  9. end
  10. elements=prod(s,2);
  11. if (length(c) <elements(end)) | ~(elements(1)+3*sum(elements(2:end-1))>=elements(end))
  12.     error(['[C S] must be a standard wavelet decomposition structure.']);
  13. end
  14. nmax=size(s,1)-2;
  15. wname=varargin{1};filterchk=0;nchk=0;
  16. switch nargin
  17.     case 3
  18.         if ischar(wname)
  19.             [lp,hp]=wavefilter(wname,'r');
  20.             n=nmax;
  21.         else
  22.                 error('Undefined filter.');
  23.         end
  24.         if nargout~=1
  25.             error('Wrong number of output arguments.');
  26.         end
  27.     case 4
  28.         if ischar(wname)
  29.             [lp,hp]=wavefilter(wname,'r');
  30.             n=varargin{2};nchk=1;
  31.         else
  32.             lp=varargin{1};
  33.             hp=varargin{2};
  34.             filterchk=1;n=nmax;
  35.             if nargout ~=1
  36.                 error('Wrong number of output arguments.');
  37.             end
  38.         end
  39.     case 5
  40.         lp=varargin{1};hp=varargin{2};filterchk=1;
  41.         n=varargin{3};nchk=1;
  42.     otherwise
  43.         error('Improper number of input arguments.');
  44. end
  45. fl=length(lp);
  46. if filterchk
  47.     if (ndims(lp) ~=2) | ~isreal(lp) | ~isnueric(lp) |(ndims(hp) ~=2) | ~isreal(hp) ...
  48.             | ~isnumeric(hp) |(fl ~=length(hp)) | rem(fl,2) ~=0
  49.         error(['LP and HP must be even and equal length real,numeric filter vectors.']);
  50.     end
  51. end
  52. if nchk & (~isnumeric(n) | ~isreal(n))
  53.     error('N must be a real numeric.');
  54. end
  55. if(n~=nmax) & (nargout ~=2)
  56.     error('Not enough output arguments.');
  57. end
  58. nc=c;ns=s;nnmax=nmax;
  59. for i=1:n
  60.     a=symconvup(wavecopy('a',nc,ns),lp,lp,fl,ns(3,:))+ ...
  61.         symconvup(wavecopy('h',nc,ns,nnmax),hp,lp,fl,ns(3,:))+ ...
  62.         symconvup(wavecopy('v',nc,ns,nnmax),lp,hp,fl,ns(3,:))+ ...
  63.         symconvup(wavecopy('d',nc,ns,nnmax),hp,hp,fl,ns(3,:));
  64.     nc=nc(4*prod(ns(1,:))+1:end);
  65.     nc=[a(:)' nc];
  66.     ns=ns(3:end,:);
  67.     ns=[ns(1,:);ns];
  68.     nnmax=size(ns,1)-2;
  69. end
  70. if nargout ==1
  71.     a=nc; nc=repmat(0,ns(1,:)); nc(:)=a;
  72. end
  73. varargout{1}=nc;
  74. if nargout==2
  75.     varargout{2}=ns;
  76. end

  77. function z=symconvup(x,f1,f2,fln,keep)
  78. y=zeros([2 1].*size(x));
  79. y(1:2:end,:)=x;
  80. y=conv2(y,f1');
  81. z=zeros([1 2].*size(y));
  82. z(:,1:2:end)=y;
  83. z=conv2(z,f2);
  84. z=z(fln-1:fln+keep(1)-2,fln-1:fln+keep(2)-2);
复制代码
回复 支持 反对
分享到:

使用道具 举报

 楼主| 发表于 2007-4-4 07:20 | 显示全部楼层

第二代小波变换源码

  1. %%第二代小波变换源码
  2. %%  此程序用提升法实现第二代小波变换
  3. %%  我用的是非整数阶小波变换
  4. %%  采用时域实现,步骤先列后行
  5. %%  正变换:分裂,预测,更新;
  6. %%  反变换:更新,预测,合并
  7. %%  只做一层(可以多层,而且每层的预测和更新方程不同)

  8. clear;clc;

  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. %%%%%  1.调原始图像矩阵

  12. load wbarb;  %  下载图像
  13. f=X;         %  原始图像
  14. % f=[0 0 0 0 0 0 0 0 ;...
  15. %    0 0 0 1 1 0 0 0 ;...
  16. %    0 0 2 4 4 2 0 0 ;...
  17. %    0 1 4 8 8 4 1 0 ;...
  18. %    0 1 4 8 8 4 1 0 ;...
  19. %    0 0 2 4 4 2 0 0 ;...
  20. %    0 0 0 1 1 0 0 0 ;...
  21. %    0 0 0 0 0 0 0 0 ;];  %  原始图像矩阵

  22. N=length(f);         %  图像维数
  23. T=N/2;               %  子图像维数



  24. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  25. %%%%%%%%%%%%%%%%%正变换%%%%%%%%%%%%%%%%%%%%%%%%%
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  29. %%%%   1.列变换

  30. %  A.分裂(奇偶分开)

  31. f1=f([1:2:N-1],:);  %  奇数
  32. f2=f([2:2:N],:);    %  偶数

  33. % f1(:,T+1)=f1(:,1);  %  补列
  34. % f2(T+1,:)=f2(1,:);  %  补行

  35. %  B.预测

  36. for i_hc=1:T;
  37.     high_frequency_column(i_hc,:)=f1(i_hc,:)-f2(i_hc,:);
  38. end;

  39. % high_frequency_column(T+1,:)=high_frequency_column(1,:);  %  补行

  40. %  C.更新

  41. for i_lc=1:T;
  42.     low_frequency_column(i_lc,:)=f2(i_lc,:)+1/2*high_frequency_column(i_lc,:);
  43. end;

  44. %  D.合并
  45. f_column([1:1:T],:)=low_frequency_column([1:T],:);
  46. f_column([T+1:1:N],:)=high_frequency_column([1:T],:);
  47.    
  48.    
  49. figure(1)
  50. colormap(map);
  51. image(f);

  52. figure(2)
  53. colormap(map);
  54. image(f_column);


  55. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  56. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  57. %%%%   2.行变换

  58. %  A.分裂(奇偶分开)

  59. f1=f_column(:,[1:2:N-1]);  %  奇数
  60. f2=f_column(:,[2:2:N]);    %  偶数


  61. % f2(:,T+1)=f2(:,1);    %  补行

  62. %  B.预测

  63. for i_hr=1:T;
  64.     high_frequency_row(:,i_hr)=f1(:,i_hr)-f2(:,i_hr);
  65. end;

  66. % high_frequency_row(:,T+1)=high_frequency_row(:,1);  %  补行

  67. %  C.更新

  68. for i_lr=1:T;
  69.     low_frequency_row(:,i_lr)=f2(:,i_lr)+1/2*high_frequency_row(:,i_lr);
  70. end;

  71. %  D.合并
  72. f_row(:,[1:1:T])=low_frequency_row(:,[1:T]);
  73. f_row(:,[T+1:1:N])=high_frequency_row(:,[1:T]);
  74.    

  75. figure(3)
  76. colormap(map);
  77. image(f_row);





  78. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  79. %%%%%%%%%%%%%%%%%%%反变换%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




  81. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  82. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  83. %%%%   1.行变换

  84. %   A.提取(低频高频分开)

  85. f1=f_row(:,[T+1:1:N]);  %  奇数
  86. f2=f_row(:,[1:1:T]);    %  偶数


  87. % f2(:,T+1)=f2(:,1);    %  补行

  88. %  B.更新

  89. for i_lr=1:T;
  90.     low_frequency_row(:,i_lr)=f2(:,i_lr)-1/2*f1(:,i_lr);
  91. end;

  92. %  C.预测

  93. for i_hr=1:T;
  94.     high_frequency_row(:,i_hr)=f1(:,i_hr)+low_frequency_row(:,i_hr);
  95. end;

  96. % high_frequency_row(:,T+1)=high_frequency_row(:,1);  %  补行


  97. %  D.合并(奇偶分开合并)
  98. f_row(:,[2:2:N])=low_frequency_row(:,[1:T]);
  99. f_row(:,[1:2:N-1])=high_frequency_row(:,[1:T]);
  100.    

  101. figure(4)
  102. colormap(map);
  103. image(f_row);


  104. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  105. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  106. %%%%   2.列变换

  107. %  A.提取(低频高频分开)

  108. f1=f_row([T+1:1:N],:);  %  奇数
  109. f2=f_row([1:1:T],:);    %  偶数

  110. % f1(:,T+1)=f1(:,1);  %  补列
  111. % f2(T+1,:)=f2(1,:);  %  补行

  112. %  B.更新

  113. for i_lc=1:T;
  114.     low_frequency_column(i_lc,:)=f2(i_lc,:)-1/2*f1(i_lc,:);
  115. end;

  116. %  C.预测

  117. for i_hc=1:T;
  118.     high_frequency_column(i_hc,:)=f1(i_hc,:)+low_frequency_column(i_hc,:);
  119. end;

  120. % high_frequency_column(T+1,:)=high_frequency_column(1,:);  %  补行



  121. %  D.合并(奇偶分开合并)
  122. f_column([2:2:N],:)=low_frequency_column([1:T],:);
  123. f_column([1:2:N-1],:)=high_frequency_column([1:T],:);
  124.    
  125.    
  126. figure(5)
  127. colormap(map);
  128. image(f_column);
复制代码
 楼主| 发表于 2007-4-4 07:24 | 显示全部楼层

利用小波变换实现对电能质量检测的算法实现

  1. N=10000;
  2. s=zeros(1,N);
  3. for n=1:N        
  4.     if n<0.4*N||n>0.8*N      
  5.         s(n)=31.1*sin(2*pi*50/10000*n);   
  6.     else        
  7.         s(n)=22.5*sin(2*pi*50/10000*n);     
  8.     end
  9. end
  10. l=length(s);
  11. [c,l]=wavedec(s,6,'db5'); %用db5小波分解信号到第六层
  12. subplot(8,1,1);
  13. plot(s);
  14. title('用db5小波分解六层:s=a6+d6+d5+d4+d3+d2+d1');
  15. Ylabel('s');%对分解结构【c,l】中第六层低频部分进行重构
  16. a6=wrcoef('a',c,l,'db5',6);
  17. subplot(8,1,2);
  18. plot(a6);
  19. Ylabel('a6');%对分解结构【c,l】中各层高频部分进行重构
  20. for i=1:6   
  21.     decmp=wrcoef('d',c,l,'db5',7-i);   
  22.     subplot(8,1,i+2);   
  23.     plot(decmp);   
  24.     Ylabel(['d',num2str(7-i)]);
  25. end
  26. %-----------------------------------------------------------
  27. rec=zeros(1,300);
  28. rect=zeros(1,300);
  29. ke=1;
  30. u=0;
  31. d1=wrcoef('d',c,l,'db5',1);
  32. figure(2);
  33. plot(d1);
  34. si=0;
  35. N1=0;
  36. N0=0;
  37. sce=0;
  38. for n=20:N-30
  39.   rect(ke)=s(n);
  40.   ke=ke+1;
  41.   if(ke>=301)
  42.         if(si==2)
  43.             rec=rect;
  44.             u=2;
  45.         end;
  46.         si=0;
  47.         ke=1;
  48.     end;
  49. if(d1(n)>0.01)                       % the condition of abnormal append.
  50.         N1=n;
  51.         if(N0==0)
  52.             N0=n;
  53.             si=si+1;
  54.         end;
  55.         if(N1>N0+30)
  56.             Nlen=N1-N0;
  57.             Tab=Nlen/10000;
  58.         end;
  59.     end;

  60. if(si==1)
  61.     for k=N0:N0+99                       %testing of 1/4 period signals to
  62.        sce=sce+s(k)*s(k)/10000;
  63.     end;
  64.     re=sqrt(sce*200)                   %re indicate the pike value of .
  65.     sce=0;
  66.     si=si+1;
  67.   end;
  68. end;
  69.   Nlen
  70.   N0
  71.   n=1:300;
  72.   figure(3)
  73.   plot(n,rec);
复制代码
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2007-4-4 07:25 | 显示全部楼层

基于小波变换的图象去噪 Normalshrink算法

  1. function [T_img,Sub_T]=threshold_2_N(img,levels)

  2. % reference :image denoising using wavelet thresholding

  3. [xx,yy]=size(img);
  4. HH=img((xx/2+1):xx,(yy/2+1):yy);

  5. delt_2=(std(HH(:)))^2;%(median(abs(HH(:)))/0.6745)^2;%

  6. T_img=img;

  7. for i=1:levels
  8.       
  9.     temp_x=xx/2^i;
  10.     temp_y=yy/2^i;
  11. %     belt=1.0*(log(temp_x/(2*levels)))^0.5;
  12.      belt=1.0*(log(temp_x/(2*levels)))^0.5;  %2.5 0.8
  13.    %HL
  14.     HL=img(1:temp_x,(temp_y+1):2*temp_y);
  15.    
  16.     delt_y=std(HL(:));
  17.     T_1=belt*delt_2/delt_y;
  18.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19.     T_HL=sign(HL).*max(0,abs(HL)-T_1);

  20.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  21.     T_img(1:temp_x,(temp_y+1):2*temp_y)=T_HL;
  22.    
  23.     Sub_T(3*(i-1)+1)=T_1;
  24.       
  25.    %LH
  26.     LH=img((temp_x+1):2*temp_x,1:temp_y);
  27.    
  28.     delt_y=std(LH(:));
  29.     T_2=belt*delt_2/delt_y;
  30.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31.     T_LH=sign(LH).*max(0,abs(LH)-T_2);
  32.    
  33.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34.     T_img((temp_x+1):2*temp_x,1:temp_y)=T_LH;
  35.    
  36.     Sub_T(3*(i-1)+2)=T_2;
  37.    
  38.    %HH
  39.     HH=img((temp_x+1):2*temp_x,(temp_y+1):2*temp_y);
  40.    
  41.     delt_y=std(HH(:));
  42.     T_3=belt*delt_2/delt_y;
  43.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  44.     T_HH=sign(HH).*max(0,abs(HH)-T_3);
  45.    
  46.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47.     T_img((temp_x+1):2*temp_x,(temp_y+1):2*temp_y)=T_HH;
  48.    
  49.     Sub_T(3*(i-1)+3)=T_3;
  50. end
复制代码
 楼主| 发表于 2007-4-4 07:28 | 显示全部楼层

基于小波变换模极大的多尺度图像边缘检测

  1. clear all;
  2. load wbarb;
  3. I = ind2gray(X,map);imshow(I);
  4. I1 = imadjust(I,stretchlim(I),[0,1]);figure;imshow(I1);
  5. [N,M] = size(I);

  6. h = [0.125,0.375,0.375,0.125];
  7. g = [0.5,-0.5];
  8. delta = [1,0,0];

  9. J = 3;

  10. a(1:N,1:M,1,1:J+1) = 0;
  11. dx(1:N,1:M,1,1:J+1) = 0;
  12. dy(1:N,1:M,1,1:J+1) = 0;
  13. d(1:N,1:M,1,1:J+1) = 0;

  14. a(:,:,1,1) = conv2(h,h,I,'same');
  15. dx(:,:,1,1) = conv2(delta,g,I,'same');
  16. dy(:,:,1,1) = conv2(g,delta,I,'same');

  17. x = dx(:,:,1,1);
  18. y = dy(:,:,1,1);
  19. d(:,:,1,1) = sqrt(x.^2+y.^2);
  20. I1 = imadjust(d(:,:,1,1),stretchlim(d(:,:,1,1)),[0 1]);figure;imshow(I1);

  21. lh = length(h);
  22. lg = length(g);

  23. for j = 1:J+1
  24.   lhj = 2^j*(lh-1)+1;
  25.   lgj = 2^j*(lg-1)+1;
  26.   hj(1:lhj)=0;
  27.   gj(1:lgj)=0;
  28.   for n = 1:lh
  29.     hj(2^j*(n-1)+1)=h(n);
  30.   end

  31.   for n = 1:lg
  32.     gj(2^j*(n-1)+1)=g(n);
  33.   end
  34.   
  35.   a(:,:,1,j+1) = conv2(hj,hj,a(:,:,1,j),'same');
  36.   dx(:,:,1,j+1) = conv2(delta,gj,a(:,:,1,j),'same');
  37.   dy(:,:,1,j+1) = conv2(gj,delta,a(:,:,1,j),'same');

  38.   x = dx(:,:,1,j+1);
  39.   y = dy(:,:,1,j+1);
  40.   dj(:,:,1,j+1) = sqrt(x.^2+y.^2);

  41.   I1 = imadjust(dj(:,:,1,j+1),stretchlim(dj(:,:,1,j+1)),[0 1]);figure;imshow(I1);
  42. end  
复制代码
 楼主| 发表于 2007-4-4 07:31 | 显示全部楼层

利用小波变根据二进制数(水印)来改变图片,提取其中一个子带的直方图

  1. close all
  2. clear all
  3. clc;

  4. Original_image = imread('lena512_marked.bmp');
  5. Original_image = double(Original_image);
  6. [ll1,h1,v1]=ADWT2(Original_image,1);
  7. HL1 = v1{1};
  8. HL1_1D = sort(HL1(:)).';
  9. bin_size = 2;
  10. range_value = 81;
  11. step =[-range_value:bin_size:range_value];
  12. Extract_histogram1 = histc(HL1_1D,step);  % 提取的 histogram 步长为1
  13. % Extract_histogram1 = histc(HL1_1D,[floor(min(HL1_1D)):2:(floor(max(HL1_1D))+1)]);
  14. [m1,n1] = size(Extract_histogram1);
  15. relation1 = zeros(1,n1);
  16. for i = 2:3:(n1/2)
  17.     relation1(1,i) = 2*Extract_histogram1(1,i)/(Extract_histogram1(1,i+1)+Extract_histogram1(1,i-1));
  18. end
  19. for i = ((n1/2)+4):3:(n1-2)
  20.     relation1(1,i) = 2*Extract_histogram1(1,i)/(Extract_histogram1(1,i+1)+Extract_histogram1(1,i-1));
  21. end

  22. %%% Extract watermark W
  23. W_number1 = 24;         % 水印的个数 W_number
  24. H1 = zeros(1,3*W_number1);
  25. H1(1:(3*W_number1/2)) = Extract_histogram1(1:(3*W_number1/2));  % H的第一个直方图的起点是-range_value
  26. H1((3*W_number1/2+1):3*W_number1) = Extract_histogram1((n1/2+3):(n1/2+2+3*W_number1/2));% H的第(2*W_number+1)个直方图的起点是-range_value+bin_size*n/2
  27. a = zeros(1,W_number1);
  28. b = zeros(1,W_number1);
  29. c = zeros(1,W_number1);
  30. H_matrix1 = reshape(H1,3,W_number1);
  31. a = H_matrix1(1,:);
  32. b = H_matrix1(2,:);
  33. c = H_matrix1(3,:);    % a(i),b(i) and c(i) 是嵌入第i个水印的三个bin的大小
  34. extract_W1=zeros(1,W_number1);
  35. for i=1:W_number1
  36.     if (2*b(1,i) >= a(1,i)+c(1,i))
  37.         extract_W1(1,i)=1;
  38.     else if (2*b(1,i) < (a(1,i)+c(1,i)))
  39.         extract_W1(1,i)=-1;
  40.         end
  41.     end
  42. end
  43. extract_watermark1=extract_W1

  44. %%% 缩小
  45. Original_image = imread('lena512_marked.bmp');
  46. % scaled_image = imresize(Original_image,[450,450]);
  47. scaled_image = imresize(Original_image,.9);
  48. scaled_image = double(scaled_image);
  49. [ll2,h2,v2]=ADWT2(scaled_image,1);
  50. HL2 = v2{1};
  51. HL2_1D = sort(HL2(:)).';    % 将HL子带变为一维向量
  52. Extract_histogram2 = histc(HL2_1D,step);    % 提取的 histogram 步长为1
  53. [m2,n2] = size(Extract_histogram2);
  54. % hist(sort(HL(:)),n);
  55. relation2 = zeros(1,n1);
  56. for i = 2:3:(n1/2)
  57.     relation2(1,i) = 2*Extract_histogram2(1,i)/(Extract_histogram2(1,i+1)+Extract_histogram2(1,i-1));
  58. end
  59. for i = ((n1/2)+4):3:(n1-2)
  60.     relation2(1,i) = 2*Extract_histogram2(1,i)/(Extract_histogram2(1,i+1)+Extract_histogram2(1,i-1));
  61. end

  62. %%% Extract watermark W
  63. W_number2 = 24;         % 水印的个数 W_number
  64. H2 = zeros(1,3*W_number2);
  65. H2(1:(3*W_number2/2)) = Extract_histogram2(1:(3*W_number2/2));  % H的第一个直方图的起点是-range_value
  66. H2((3*W_number2/2+1):3*W_number2) = Extract_histogram2((n2/2+3):(n2/2+2+3*W_number2/2));% H的第(2*W_number+1)个直方图的起点是-range_value+bin_size*n/2
  67. a = zeros(1,W_number2);
  68. b = zeros(1,W_number2);
  69. c = zeros(1,W_number2);
  70. H_matrix2 = reshape(H2,3,W_number2);
  71. a = H_matrix2(1,:);
  72. b = H_matrix2(2,:);
  73. c = H_matrix2(3,:);    % a(i),b(i) and c(i) 是嵌入第i个水印的三个bin的大小
  74. extract_W2=zeros(1,W_number2);
  75. for i=1:W_number2
  76.     if (2*b(1,i) >= a(1,i)+c(1,i))
  77.         extract_W2(1,i)=1;
  78.     else if (2*b(1,i) < (a(1,i)+c(1,i)))
  79.         extract_W2(1,i)=-1;
  80.         end
  81.     end
  82. end
  83. extract_watermark2=extract_W2


  84. %%% 放大
  85. Original_image = imread('lena512_marked.bmp');
  86. scaled_image = imresize(Original_image,1.3);
  87. scaled_image = double(scaled_image);
  88. [ll3,h3,v3]=ADWT2(scaled_image,1);
  89. HL3 = v3{1};
  90. HL3_1D = sort(HL3(:)).';    % 将HL子带变为一维向量
  91. Extract_histogram3 = histc(HL3_1D,step);    % 提取的 histogram 步长为1
  92. [m3,n3] = size(Extract_histogram3);
  93. % hist(sort(HL(:)),n);
  94. relation3 = zeros(1,n1);
  95. for i = 2:3:(n1/2)
  96.     relation3(1,i) = 2*Extract_histogram3(1,i)/(Extract_histogram3(1,i+1)+Extract_histogram3(1,i-1));
  97. end
  98. for i = ((n1/2)+4):3:(n1-2)
  99.     relation3(1,i) = 2*Extract_histogram3(1,i)/(Extract_histogram3(1,i+1)+Extract_histogram3(1,i-1));
  100. end

  101. %%% Extract watermark W
  102. W_number3 = 24;         % 水印的个数 W_number
  103. H3 = zeros(1,3*W_number3);
  104. H3(1:(3*W_number3/2)) = Extract_histogram3(1:(3*W_number3/2));  % H的第一个直方图的起点是-range_value
  105. H3((3*W_number3/2+1):3*W_number3) = Extract_histogram3((n3/2+3):(n3/2+2+3*W_number3/2));% H的第(2*W_number+1)个直方图的起点是-range_value+bin_size*n/2
  106. a = zeros(1,W_number3);
  107. b = zeros(1,W_number3);
  108. c = zeros(1,W_number3);
  109. H_matrix3 = reshape(H3,3,W_number3);
  110. a = H_matrix3(1,:);
  111. b = H_matrix3(2,:);
  112. c = H_matrix3(3,:);    % a(i),b(i) and c(i) 是嵌入第i个水印的三个bin的大小
  113. extract_W3=zeros(1,W_number3);
  114. for i=1:W_number3
  115.     if (2*b(1,i) >= a(1,i)+c(1,i))
  116.         extract_W3(1,i)=1;
  117.     else if (2*b(1,i) < (a(1,i)+c(1,i)))
  118.         extract_W3(1,i)=-1;
  119.         end
  120.     end
  121. end
  122. extract_watermark3=extract_W3

  123. %%% 旋转
  124. Original_image = imread('lena512_marked.bmp');
  125. Rescale_image = imrotate(Original_image,10);
  126. Rescale_image = double(Rescale_image);
  127. [ll4,h4,v4]=ADWT2(Rescale_image,1);
  128. HL4 = v4{1};
  129. HL4_1D = sort(HL4(:)).';    % 将HL子带变为一维向量
  130. Extract_histogram4 = histc(HL4_1D,step);    % 提取的 histogram 步长为1
  131. [m4,n4] = size(Extract_histogram4);
  132. % hist(sort(HL(:)),n);
  133. relation4 = zeros(1,n1);
  134. for i = 2:3:(n1/2)
  135.     relation4(1,i) = 2*Extract_histogram4(1,i)/(Extract_histogram4(1,i+1)+Extract_histogram4(1,i-1));
  136. end
  137. for i = ((n1/2)+4):3:(n1-2)
  138.     relation4(1,i) = 2*Extract_histogram4(1,i)/(Extract_histogram4(1,i+1)+Extract_histogram4(1,i-1));
  139. end

  140. %%% Extract watermark W
  141. W_number4 = 24;         % 水印的个数 W_number4
  142. H4 = zeros(1,3*W_number4);
  143. H4(1:(3*W_number4/2)) = Extract_histogram4(1:(3*W_number4/2));  % H的第一个直方图的起点是-range_value
  144. H4((3*W_number4/2+1):3*W_number4) = Extract_histogram4((n4/2+3):(n4/2+2+3*W_number4/2));% H的第(2*W_number+1)个直方图的起点是-range_value+bin_size*n/2
  145. a = zeros(1,W_number4);
  146. b = zeros(1,W_number4);
  147. c = zeros(1,W_number4);
  148. H_matrix4 = reshape(H4,3,W_number4);
  149. a = H_matrix4(1,:);
  150. b = H_matrix4(2,:);
  151. c = H_matrix4(3,:);    % a(i),b(i) and c(i) 是嵌入第i个水印的三个bin的大小
  152. extract_W4=zeros(1,W_number4);
  153. for i=1:W_number4
  154.     if (2*b(1,i) >= a(1,i)+c(1,i))
  155.         extract_W4(1,i)=1;
  156.     else if (2*b(1,i) < (a(1,i)+c(1,i)))
  157.         extract_W4(1,i)=-1;
  158.         end
  159.     end
  160. end
  161. extract_watermark4=extract_W4

  162. X1=2:1:(n1-2);
  163. Y1=relation1(1,X1);
  164. X2=2:1:(n1-2);
  165. Y2=relation2(1,X2);
  166. X3=2:1:(n1-2);
  167. Y3=relation3(1,X3);
  168. X4=2:1:(n1-2);
  169. Y4=relation4(1,X4);
  170. figure;plot(X1,Y1,'r*',X2,Y2,'b+',X3,Y3,'kd',X4,Y4,'gd');
  171. title('The estimation of bin relation');
复制代码
 楼主| 发表于 2007-4-4 07:35 | 显示全部楼层

用小波函数构建神经网络的源程序

该程序是用小波函数构建神经网络的源程序。用以分析心电信号、脑电信号等等。

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. clear all
  3. load data
  4. M1=20;
  5. epo=15;
  6. A=4;
  7. B=18;
  8. B2=B/2+1
  9. N=500;
  10. M=(A+1)*(B+1);
  11. for  a0=1:A+1;
  12. for  b0=1:B+1;
  13. i=(B+1)*(a0-1)+b0;
  14. b_init(i)=((b0-B2)/10)/(2^(-A)); a_init(i)=1/(2^(-A));
  15. c_init(i)=(20-A)/2;
  16. end
  17. end
  18. w0=ones(1,M);
  19.           for i=1:N            
  20.               for j=1:M           
  21.                   t=x(i);
  22.                   t= a_init(j)*t-b_init(j);
  23.                  %P0(i,j)= (cos(1.75*t)*exp(-t*t/2))/2^c_init(j);
  24.                  P0(i,j)= ((1-t*t)*exp(-t*t/2))/2^c_init(j);
  25.              end
  26.           end
  27. %calculation of output of network
  28.            for i=1:N
  29.                  u=0;
  30.                  for j=1:M
  31.                      u=u+w0(j)*P0(i,j);%w0?aè¨?μ
  32.                  end
  33.                  y0(i)= u;% y(p)= u=??W(j)*phi(p,j)= ??W(j)* |μj(t)
  34.            end
  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  36. for k=1:M
  37.     W(:,k)=P0(:,k);
  38. end
  39. for k=2:M
  40.     u=0;
  41.    
  42.      for      i=1:k-1   
  43.               aik(i)=(P0(:,k)'*W(:,i))/(W(:,i)'*W(:,i));
  44.               u=u+aik(i) *W(:,i);
  45.               
  46.      end
  47.      W(:,k)=P0(:,k)-u;
  48. end

  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  50. for   i=1:M                        
  51.      g(i)= (W(:,i)'*d')/( W(:,i)'* W(:,i));
  52. end
  53. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  54. u=0;
  55. for    i=1:M
  56.        u=u+g(i)*(W(:,i)'*W(:,i));
  57. end

  58. DD=u;

  59. for    i=1:M
  60.        Erro(i)=(g(i)^2)*(W(:,i)'*W(:,i))/DD;
  61. end
  62. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  63. k=1;

  64. while(k<=M1)
  65.     u=1;
  66.     for  i=2:M
  67.          if   abs(Erro(u))<abs(Erro(i));
  68.               u=i
  69.          else u=u
  70.          end
  71.     end
  72.     I(k)=u;
  73.     Erro(u)=0
  74. k=k+1;  
  75. end
  76. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  77. for k=1:M1
  78.     u=I(k);
  79.     a(k)=a_init(u);
  80.     b(k)=b_init(u);
  81.     c(k)=c_init(u);
  82.     w1(k)=w0(u);
  83. end
  84. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  85. epoch=1;

  86. error=0.1;
  87. err=0.0001;
  88. lin=0.5;

  89. while (error>=err & epoch<=epo)
  90.           for i=1:N            
  91.               for j=1:M1        
  92.                   t=x(i);
  93.                   t= a(j)*t-b(j);
  94.                  %P1(i,j)= (cos(1.75*t)*exp(-t*t/2))/2^c(j);
  95.                  P1(i,j)= ((1-t*t)*exp(-t*t/2))/2^c(j);
  96.              end
  97.           end
  98. %calculation of output of network
  99.            for i=1:N
  100.                  u=0;
  101.                  for j=1:M1
  102.                      u=u+w1(j)*P1(i,j);
  103.                  end
  104.                  y1(i)= u;
  105.            end
  106. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  107.    u=0;
  108.      for i=1:N
  109.             u=u+(d(i)-y1(i))^2;
  110.      end
  111.     u=u/2;%u=1/2??(d-p)^2
  112. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  113. if   u>error
  114. lin=lin*0.8;
  115. else
  116. lin=lin*1.2;
  117. end
  118. error=u; %error=u=1/2??(d-p)^2
  119. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  120.          for j=1:M1   
  121.              u=0;
  122.              for i=1:N
  123.                  u=u+(d(i)-y1(i))*P1(i,j);
  124.              end
  125.              EW(j)=-u;
  126.           end
  127.    if    epoch==1
  128.        SW=-EW;
  129.        w1_=w1;
  130.       
  131.    else
  132.    SW=-EW+((EW*EW')*SW_)/(EW_*EW_');
  133.    end
  134.    EW_=EW;
  135.    SW_=SW;
  136.     w1=w1_+SW*lin;
  137.     w1_=w1;
  138.   
  139.     %number of epoch increase by 1
  140. epoch=epoch+1;
  141. end
  142. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  143. subplot(2,1,1);plot(x,d);
  144. subplot(2,1,2);plot(x,y1);
复制代码
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2007-4-4 07:36 | 显示全部楼层

利用小波和霍夫曼对单声道文件进行压缩编码 并解码输出

  1. x=wavread('vqdeout.wav');
  2. subplot(3,2,1);
  3. plot(x);
  4. [c,l]=wavedec(x,3,'db1');
  5. cA3=appcoef(c,l,'db1',3);
  6. [cD1,cD2,cD3] = detcoef(c,l,[1 2 3]);
  7. subplot(3,2,2);
  8. plot(cA3);
  9. subplot(3,2,3);
  10. plot(cD1);
  11. subplot(3,2,4);
  12. plot(cD2);
  13. subplot(3,2,5);
  14. plot(cD3);

  15. %quantize
  16. [partition,codebook]=py_quantize(cA3);                  
  17. [index,quants]=quantiz(cA3,partition,codebook);                 
  18. [partition1,codebook1]=py_quantize(cD1);
  19. [index1,quants1]=quantiz(cD1,partition1,codebook1);               
  20. [partition2,codebook2]=py_quantize(cD2);
  21. [index2,quants2]=quantiz(cD2,partition2,codebook2);               
  22. [partition3,codebook3]=py_quantize(cD3);
  23. [index3,quants3]=quantiz(cD3,partition3,codebook3);               

  24. %probability
  25. g=py_probability(quants,l(1,1),codebook);
  26. g1=py_probability(quants1,l(4,1),codebook1);
  27. g2=py_probability(quants2,l(3,1),codebook2);
  28. g3=py_probability(quants3,l(2,1),codebook3);



  29. %huffman编解码
  30. [dict,avglen] = huffmandict(codebook,g);
  31. comp = huffmanenco(quants,dict); % Encode the data.
  32. dsig = huffmandeco(comp,dict);
  33. isequal(quants,dsig)

  34. %huffman编解码
  35. [dict1,avglen1] = huffmandict(codebook1,g1);
  36. comp1 = huffmanenco(quants1,dict1); % Encode the data.
  37. dsig1 = huffmandeco(comp1,dict1);
  38. isequal(quants1,dsig1)

  39. %huffman编解码
  40. [dict2,avglen2] = huffmandict(codebook2,g2);
  41. comp2 = huffmanenco(quants2,dict2); % Encode the data.
  42. dsig2 = huffmandeco(comp2,dict2);
  43. isequal(quants2,dsig2)

  44. %huffman编解码
  45. [dict3,avglen3] = huffmandict(codebook3,g3);
  46. comp3 = huffmanenco(quants3,dict3); % Encode the data.
  47. dsig3 = huffmandeco(comp3,dict3);
  48. isequal(quants3,dsig3)

  49. %dsig3=dsig3';
  50. %dsig2=dsig2';
  51. %dsig1=dsig1';
  52. %dsig=dsig';
  53. %重构
  54. cA2=idwt(dsig,dsig3,'db1');
  55. icA2(1:13950)=cA2(1:13950);
  56. cA1=idwt(icA2,dsig2,'db1');
  57. icA1(1:27899)=cA1(1:27899);
  58. XX=idwt(icA1,dsig1,'db1');
  59. XX=XX';
  60. subplot(3,2,6);
  61. plot(XX);

  62. MSE=sum((x-XX).^2)/length(XX);
  63. PSNR=10*log10((max(max(XX)))^2/MSE);
复制代码
 楼主| 发表于 2007-4-4 07:38 | 显示全部楼层

用小波神经网络来对时间序列进行预测


  1. %File name :       nprogram.m
  2. %Description   :   This   file   reads   the  data   from   its   source   into   their   respective  matrices   prior   to
  3.   %                  performing wavelet decomposition.

  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. %Clear command screen and variables
  6. clc;
  7. clear;

  8. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. % user desired resolution level (Tested: resolution = 2 is best)
  10. level = menu('Enter desired resolution level: ', '1',...
  11.                   '2 (Select this for testing)', '3', '4');
  12. switch level
  13.       case 1, resolution = 1;
  14.       case 2, resolution = 2;
  15.       case 3, resolution = 3;
  16.       case 4, resolution = 4;
  17. end

  18. msg = ['Resolution level to be used is ', num2str(resolution)];
  19. disp(msg);

  20. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  21. % user desired amount of data to use
  22. data = menu('Choose amount of data to use: ', '1 day', '2 days', '3 days', '4 days',...
  23.                  '5 days', '6 days', '1 week (Select this for testing)');
  24. switch data
  25.       case 1, dataPoints = 48;        %1 day = 48 points
  26.       case 2, dataPoints = 96;        %2 days = 96 points
  27.       case 3, dataPoints = 144;       %3 days = 144 points
  28.       case 4, dataPoints = 192;       %4 days = 192 points
  29.       case 5, dataPoints = 240;       %5 days = 240 points
  30.       case 6, dataPoints = 288;       %6 days = 288 points
  31.       case 7, dataPoints = 336;       %1 weeks = 336 points

  32. end

  33. msg = ['No. of data points to be used is ', num2str(dataPoints)];
  34. disp(msg);

  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  36. %Menu for data set selection
  37. select = menu('Use QLD data of: ', 'Jan02',...
  38.                     'Feb02', 'Mar02 (Select this for testing)', 'Apr02', 'May02');
  39. switch select
  40.       case 1, demandFile = 'DATA200601_QLD1';

  41.       case 2, demandFile = 'DATA200602_QLD1';

  42.       case 3, demandFile = 'DATA200603_QLD1';

  43.       case 4, demandFile = 'DATA200604_QLD1';

  44.       case 5, demandFile = 'DATA200605_QLD1';
  45. end

  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. %Reading the historical DEMAND data into tDemandArray
  48. selectedDemandFile=[demandFile,'.csv'];
  49. [regionArray, sDateArray, tDemandArray, rrpArray, pTypeArray] ...
  50. = textread(selectedDemandFile, '%s %q %f %f %s', 'headerlines', 1, 'delimiter', ',');

  51. %Display no. of points in the selected time series demand data
  52. [demandDataPoints, y] = size(tDemandArray);
  53. msg = ['The no. of points in the selected Demand data is ', num2str(demandDataPoints)];
  54. disp(msg);

  55. %Decompose historical demand data signal
  56. [dD, l] = swtmat(tDemandArray, resolution, 'db2');
  57. approx = dD(resolution, :);

  58. %Plot the original demand data signal
  59. figure (1);
  60. subplot(resolution + 2, 1, 1); plot(tDemandArray(1: dataPoints))
  61. legend('Demand Original');
  62. title('QLD Demand Data Signal');

  63. %Plot the approximation demand data signal
  64. for i = 1 : resolution
  65.       subplot(resolution + 2, 1, i     + 1); plot(approx(1: dataPoints))
  66.       legend('Demand Approximation');
  67. end

  68. %After displaying approximation signal, display detail x
  69. for i = 1: resolution
  70.     if( i > 1 )
  71.             detail(i, :) = dD(i-1, :)- dD(i, :);
  72.       else
  73.             detail(i, :) = tDemandArray' - dD(1, :);
  74.       end

  75.            if i == 1
  76.                  subplot(resolution + 2, 1, resolution - i + 3); plot(detail(i, 1: dataPoints))
  77.                  legendName = ['Demand Detail ', num2str(i)];
  78.                   legend(legendName);

  79.             else
  80.                  subplot(resolution + 2, 1, resolution - i + 3); plot(detail(i, 1: dataPoints))
  81.                  legendName = ['Demand Detail ', num2str(i)];
  82.                  legend(legendName);

  83.             end

  84.     i = i + 1;
  85. end

  86. %Normalising approximation demand data
  87. maxDemand = max(approx'); %Find largest component
  88. normDemand = approx ./ maxDemand; %Right divison

  89. maxDemandDetail = [ ];
  90. normDemandDetail = [, ];

  91. detail = detail + 4000;

  92. for i = 1: resolution
  93.       maxDemandDetail(i) = max(detail(i, :));
  94.       normDemandDetail(i, :) = detail(i, :) ./maxDemandDetail(i);
  95. end

  96. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  97. %Reading the historical historical PRICE data into rrpArray
  98. selectedPriceFile = [demandFile, '.csv'];
  99. [regionArray, sDateArray, tDemandArray, rrpArray, pTypeArray] ...
  100. = textread(selectedDemandFile, '%s %q %f %f %s', 'headerlines', 1, 'delimiter', ',');

  101. %Display no. of points in Price data
  102. [noOfDataPoints, y] = size(rrpArray);
  103. msg = ['The no. of points in Price data data is ', num2str(noOfDataPoints)];
  104. disp(msg);

  105. %Decompose historical Price data signal
  106. [dP, l] = swtmat(rrpArray, resolution, 'db2');
  107. approxP = dP(resolution, :);

  108. %Plot the original Price data signal
  109. figure (2);
  110. subplot(resolution + 3, 1, 1); plot(rrpArray(2: dataPoints))
  111. legend('Price Original');
  112. title('Price Data Signal');

  113. %Plot the approximation Price data signal
  114. for i = 1 : resolution
  115.       subplot(resolution + 3, 1, i + 1); plot(approxP(2: dataPoints))
  116.       legend('Price Approximation');
  117. end

  118. %After displaying approximation signal, display detail x
  119. for i = 1: resolution
  120.      if( i > 1 )
  121.             detailP(i, :) = dP(i-1, :)- dP(i, :);
  122.       else
  123.             detailP(i, :) = rrpArray' - dP(1, :);
  124.       end

  125. if i == 1
  126.       [B,A]=butter(1,0.65,'low');
  127.       result =filter(B,A, detailP(i, 1: dataPoints));

  128.       subplot(resolution + 3, 1, resolution - i + 4);plot(result(i, 2: dataPoints))
  129.       legendName = ['low pass filter', num2str(i)];
  130.       legend(legendName);

  131.       subplot(resolution + 3, 1, resolution - i + 3); plot(detailP(i, 2: dataPoints))
  132.       legendName = ['Price Detail ', num2str(i)];
  133.       legend(legendName);

  134. else
  135.       subplot(resolution + 3, 1, resolution - i + 3); plot(detailP(i, 2: dataPoints))
  136.       legendName = ['Price Detail ', num2str(i)];
  137.       legend(legendName);

  138. end
  139.      i = i + 1;
  140. end

  141. %Normalising approximation Price data
  142. maxPrice = max(approxP'); %Find largest component
  143. normPrice = approxP ./ maxPrice; %Right divison

  144. maxPriceDetail = [ ];
  145. normPriceDetail = [, ];

  146. detailP = detailP + 40;

  147. for i = 1: resolution
  148.       maxPriceDetail(i) = max(detailP(i, :));
  149.       normPriceDetail(i, :) = detailP(i, :) ./maxPriceDetail(i);
  150. end

  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152. %Function here allows repetitive options to,
  153. %      1) Create new NNs, 2) Retrain the existing NNs,
  154. %      3) Perform load demand forecasting and 4) Quit session

  155. while (1)

  156.       choice = menu('Please select one of the following options: ',...
  157.                           'CREATE new Neural Networks',...
  158.                           'Perform FORECASTING of load demand', 'QUIT session...');
  159.       switch choice
  160.            case 1, scheme = '1';
  161.            case 2, scheme = '2';
  162.            case 3, scheme = '3';
  163.            case 4, scheme = '4';
  164. end

  165.       %If scheme is 'c', call <nCreate> to create new NNs, train them then perform forecast
  166.       if(scheme == '1')
  167.            nCreate;
  168.       end

  169.       %If scheme is 'r', call <nRetrain> to retrain the existing NNs
  170.       if(scheme == '2')
  171.            nRetrain;
  172.       end

  173.       %If scheme is 'f', call <nForecast> to load the existing NN model
  174.       if(scheme == '3')
  175.            nForecast;
  176.       end

  177.       %If scheme is 'e', verifies and quit session if 'yes' is selected else continue
  178.       if(scheme == '4')
  179.            button = questdlg('Quit session?', 'Exit Dialog','Yes','No','No');
  180.            switch button
  181.                  case 'Yes', disp(' ');
  182.                                    disp('Session has ended!!');
  183.                                    disp(' ');
  184.                                    break;
  185.                  case 'No', quit cancel;
  186.            end
  187.       end
  188. end

  189. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  190. %File name :      ncreate.m
  191. %Description : This file prepares the input &  output data for the NNs. It creates then trains the
  192. %                  NNs to mature them.

  193. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  194. %Clear command screen and set target demand ouput to start at point 2
  195. clc;
  196. targetStartAt = 2;

  197. disp('Program will now CREATE a Neural Network for training and forecasting...');
  198. disp(' ');
  199. disp('To capture the pattern of the signal, the model is ')
  200. disp('set to accept dataPoints x 2 sets of training examples; ');
  201. disp('1 set of demand + 1 sets of price. ');
  202. disp(' ');
  203. disp('The normalised demand data <point 2>, is to be taken as the ')
  204. disp('output value for the first iteration of training examples. ');
  205. disp(' ');
  206. disp('Press ENTER key to continue...');
  207. pause;

  208. %Clear command screen then prompt for no. of training cycles
  209. %For current program, 1 cycle = user set no. of iterations (ie: dataPoints)
  210. clc;
  211. cycle = input('Input the number of training cycles: ');

  212. numOfTimes = resolution + 1;
  213. %Creating and training the NNs for the respective
  214. %demand and price coefficient signals
  215. for x = 1: numOfTimes

  216.       %Clearing variables
  217.       clear targetDemand;
  218.       clear inputs;
  219.       clear output;
  220.       clc;

  221.       if(x == 1)
  222.             neuralNetwork = ['Neural network settings for approximation level ',
  223.      num2str(resolution)];
  224.       else
  225.             neuralNetwork = ['Neural network settings for detail level ', num2str(x - 1)];
  226.       end
  227.       disp(neuralNetwork);
  228.       disp(' ');

  229.       %Set no. of input nodes and hidden neurons for the
  230.       %respective demand and price coefficient signal
  231.       numOfInputs = 2;
  232.       inputValue = ['Number of neural network INPUT units is set at ', num2str(numOfInputs)];
  233.       disp(inputValue);
  234.       disp(' ');
  235.       numOfOutput = 1;
  236.       outValue = ['Output is set to ', num2str(numOfOutput)];
  237.       disp(outValue);
  238.       disp(' ');
  239.       numOfHiddens = input('Enter the no. of HIDDEN units for the NN hidden : ');
  240.       hiddenValue = ['Number of neural network HIDDEN units is set at ',
  241.      num2str(numOfHiddens)];
  242.       disp(hiddenValue);
  243.       disp(' ');

  244.      %Setting no. of training examples
  245.      trainingLength = dataPoints;

  246.       %Set target outputs of the training examples
  247.      if(x == 1)
  248.            targetDemand = normDemand(targetStartAt: 1 + trainingLength);
  249.      else
  250.            targetDemand = normDemandDetail(x - 1, targetStartAt: 1 + trainingLength);
  251.      end

  252.      %Preparing training examples
  253.       %Setting training i/ps to be 2 with user defined no. of iterations (dataPoints)
  254.      y = 0;
  255.      while y < trainingLength
  256.            if(x == 1)
  257.                 inputs(1, y + 1) = normDemand(y + 1);
  258.                 inputs(2, y + 1) = normPrice(y + 1);

  259.            else
  260.                 inputs(1, y + 1) = normDemandDetail(x - 1, y + 1);
  261.                 inputs(2, y + 1) = normPriceDetail(x - 1, y + 1);

  262.            end

  263.            output(y + 1, :) = targetDemand(y + 1);

  264.            y = y + 1;
  265.      end

  266.      inputs = (inputs');

  267.      %Setting no. of training cycles
  268.       [ni, np] = size(targetDemand); % <== [ni, np] tells the NN how long is 1 cycle;
  269.      size(targetDemand)

  270.      clear nn;

  271.       %Create new neural network for respective coefficient signal
  272.      %NET = MLP(NIN, NHIDDEN, NOUT, FUNC)
  273.      nn = mlp(numOfInputs, numOfHiddens, numOfOutput, 'linear');

  274.      %NN options
  275.       options = zeros(1, 18);
  276.       options(1) = 1; %Provides display of error values
  277.       options(14) = cycle * ni * np;

  278.      %Training the neural network

  279.       %netopt(net, options, x, t, alg);
  280.       nn = netopt(nn, options, inputs, output, 'scg');

  281.       %Save the neural network
  282.       filename = ['nn', num2str(x)];
  283.       save(filename, 'nn');

  284.       disp(' ');
  285.       msg = ['Neural network successfully CREATED and saved as => ', filename];
  286.       disp(msg);

  287.       if(x < 3)
  288.             disp(' ');
  289.             disp('Press ENTER key to continue training the next NN...');
  290.       else
  291.             disp(' ');
  292.             disp('Model is now ready to forecast!!');
  293.             disp(' ');
  294.             disp('Press ENTER key to continue...');
  295.       end

  296.       pause;
  297. end
  298. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  299. %File name :       nforecast.m
  300. %Description : This file loads the trained NNs for load forcasting and %recombines the predicted
  301. %                   outputs from the NNs to form the final predicted load series.

  302. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  303. %Clear command screen and variables
  304. clc;
  305. clear forecastResult;
  306. clear actualDemand;
  307. clear predicted;
  308. clear actualWithPredicted;

  309. disp('Neural networks loaded, performing electricity demand forecast...');
  310. disp(' ');
  311. pointsAhead = input('Enter no. of points to predict (should be < 336): ');

  312. numOfTimes = resolution + 1;
  313. %Predict coefficient signals using respective NNs
  314. for x = 1 : numOfTimes
  315.       %Loading NN
  316.       filename = ['nn', num2str(x)];
  317.       clear nn
  318.       load(filename);
  319.       clear in;
  320.       numOfInputs = nn.nin;
  321.       y = 0;
  322.       %Preparing details to forecast
  323.       while y < pointsAhead
  324.            if(x == 1)
  325.                  propData(1, y + 1) = normDemand(y + 1);
  326.                  propData(2, y + 1) = normPrice(y + 1);

  327.            else
  328.                  propData(1, y + 1) = normDemandDetail(x - 1, y + 1);
  329.                  propData(2, y + 1) = normPriceDetail(x - 1, y + 1);

  330.            end

  331.            y = y + 1;
  332.       end

  333.       if(x == 1)
  334.            forecast = mlpfwd(nn, propData') * maxDemand;
  335.       else
  336.             forecast = mlpfwd(nn, propData') * maxDemandDetail(x - 1) - 4000;
  337.       end
  338.       forecastResult(x, :) = forecast';
  339. end

  340. %For debugging
  341. % forecastResult

  342. actualDemand = tDemandArray(2: 1 + pointsAhead);
  343. predicted = sum(forecastResult, 1)';

  344. %Calculating Mean Absolute Error
  345. AbsError = abs(actualDemand - predicted(1: pointsAhead)) ./ actualDemand;
  346. msg = ['Mean Absolute Error = ', num2str(mean(AbsError(1: pointsAhead))), ' !!'];
  347. disp(' ');
  348. disp(msg);

  349. %Plot actual time series against predicted result
  350. figure(3)
  351. actualWithPredicted(:, 1) = actualDemand;
  352. actualWithPredicted(:, 2) = predicted(1: pointsAhead);
  353. plot(actualWithPredicted);
  354. graph = ['Mean Absolute Error = ', num2str(mean(AbsError))];
  355. title(graph);
  356. legend('Actual', 'Forecasted');

  357. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  358. %File name :      nretrain.m
  359. %Description : This file loads the existing NNs and trains them again.

  360. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  361. clc;
  362. %Prompt for the starting point for training
  363. disp('Program will now RETRAIN the Neural Networks ')
  364. disp('with the SAME intial data series again...');
  365. disp(' ');
  366. disp('To capture the pattern of the signal, the model is ')
  367. disp('set to accept dataPoints x 2 sets of training examples; ');
  368. disp('1 set of demand + 1 sets of price. ');
  369. disp(' ');
  370. disp('The normalised demand data <point 2>, is to be taken as the ')
  371. disp('output value for the first iteration of training examples. ');
  372. disp(' ');
  373. msg = ['Data points to be used for reTraining the NNs is from 1 to ',...
  374.             num2str(dataPoints)];
  375. disp(msg);
  376. disp(' ');
  377. disp('Press ENTER key to continue...');
  378. pause;

  379. %Clear command screen
  380. clc;

  381. %Prompt for no. of training cycles
  382. %For current program, 1 cycle = user set no. of iterations (ie: dataPoints)
  383. cycle = input('Input number of cycles to retrain the NNs: ');

  384. numOfTimes = resolution + 1;
  385. %Loading existing NNs for training
  386. for x = 1: numOfTimes

  387.       %Re-initialising variables
  388.       clear targetDemand;
  389.       clear inputs;
  390.       clear output;
  391.       clc;

  392.       %Loading NN for the respective demand and temperature coefficient signals
  393.       filename = ['nn', num2str(x)];
  394.       clear nn
  395.       load(filename);

  396.       %Getting the size of NN
  397.       numOfInputs = nn.nin;
  398.       numOfHiddens = nn.nhidden;
  399.       numOfOutput = 1;

  400.       %Setting length of reTraining examples and target outputs
  401.       reTrainLength = dataPoints;
  402.       targetLength = reTrainLength;

  403.       targetStartAt = 2;

  404.       %Set target outputs of the training examples
  405.       if(x == 1)
  406.             targetDemand = normDemand(targetStartAt: 1 + targetLength);
  407.       else
  408.             targetDemand = normDemandDetail(x - 1, targetStartAt: 1 + targetLength);
  409.       end

  410.       %Preparing training examples
  411.       %Setting training i/ps to be 2 with user set no. of iterations (dataPoints)
  412.       y = 0;
  413.       while y < reTrainLength
  414.             if(x == 1)
  415.                   inputs(1, y + 1) = normDemand(y + 1);
  416.                   inputs(2, y + 1) = normPrice(y + 1);

  417.             else
  418.                   inputs(1, y + 1) = normDemandDetail(x - 1, y + 1);
  419.                   inputs(2, y + 1) = normPriceDetail(x - 1, y + 1);

  420.             end

  421.             output(y + 1, :) = targetDemand(y + 1);

  422.             y = y + 1;
  423.       end

  424.       inputs = (inputs');

  425.       %Setting no. of training cycles
  426.       [ni, np] = size(targetDemand); % <== [ni, np] tells the NN how long is 1 cycle;
  427.       size(targetDemand)                                %With reference to line 106

  428.       %NN options
  429.       options = zeros(1, 18);
  430.       options(1) = 1; %Provides display of error values
  431.       options(14) = cycle * ni * np;

  432.       %Training the neural network
  433.       %netopt(net, options, x, t, alg);
  434.       nn = netopt(nn, options, inputs, output, 'scg');

  435.       %Save the neural network
  436.       filename = ['nn', num2str(x)];
  437.       save(filename, 'nn');

  438.       disp(' ');
  439.       msg = ['Neural network => ', filename, ' <= successfully RETRAINED and saved!! '];

  440.       disp(msg);

  441.       if(x < 3)
  442.             disp(' ');
  443.             disp('Press ENTER key to continue training the next NN...');
  444.       else
  445.             disp(' ');
  446.             disp('Model is now ready to forecast again!!');
  447.             disp(' ');
  448.             disp('Press ENTER key to continue...');
  449.       end

  450.       pause;
  451. end
复制代码
 楼主| 发表于 2007-4-4 07:40 | 显示全部楼层

基于小波特征提取方法的图象匹配算法

  1. function feature_wl=getf_wavelet(Input)
  2.    
  3.     A=double(Input);
  4.     Xrgb=0.2990*A(:,:,1)+0.5870*A(:,:,2)+0.1140*A(:,:,3);
  5.     NbColor=255;
  6. %  WCODEMAT Extended pseudocolor matrix scaling. Y = WCODEMAT(X,NBCODES,OPT,ABSOL) returns a coded version of input
  7. % matrix X if ABSOL=0, or ABS(X) if ABSOL is  nonzero, using the first NBCODES integers.
  8. %  Coding can be done row-wise (OPT='row' or 'r'), columnwise (OPT='col' or 'c'), or globally (OPT='mat' or 'm').
  9. %  Coding uses a regular grid between the minimum and the maximum values of each row (column or matrix,respectively).
  10. %  Y = WCODEMAT(X,NBCODES) is equivalent to  Y = WCODEMAT(X,NBCODES,'mat',1).
  11.     X1=wcodemat(Xrgb,NbColor);%伪彩矩阵压缩

  12. % Function 'wavedec2' Multilevel 2-D wavelet decomposition.[C,S] = WAVEDEC2(X,N,'wname') returns the wavelet
  13. % decomposition of the matrix X at level N, using the wavelet named in string 'wname' (see WFILTERS).
  14. % Outputs are the decomposition vector C and the corresponding bookkeeping matrix S.
  15. % N must be a strictly positive integer (see WMAXLEV).
  16.    [c2,l2]=wavedec2(X1,4,'sym4');%二维小波分解

  17. % Function 'detcoef2' Extract 2-D detail coefficients.
  18. % D = detcoef2(O,C,S,N) extracts from the wavelet decomposition structure [C,S], the horizontal, vertical
  19. % or diagonal detail coefficients for O = 'h' (or 'v' or 'd',respectively), at level N. N must
  20. % be an integer such that 1 <= N <= size(S,1)-2.
  21.    ch11=detcoef2('h',c2,l2,1);%提取小波分解细节系数
  22.    ch12=detcoef2('h',c2,l2,2);
  23.    ch13=detcoef2('h',c2,l2,3);
  24.    ch14=detcoef2('h',c2,l2,4);
  25.    cv11=detcoef2('v',c2,l2,1);
  26.    cv12=detcoef2('v',c2,l2,2);
  27.    cv13=detcoef2('v',c2,l2,3);
  28.    cv14=detcoef2('v',c2,l2,4);
  29.    cd11=detcoef2('d',c2,l2,1);
  30.    cd12=detcoef2('d',c2,l2,2);
  31.    cd13=detcoef2('d',c2,l2,3);
  32.    cd14=detcoef2('d',c2,l2,4);

  33. % Function 'appcoef2' Extract 2-D approximation coefficients.APPCOEF2 computes the approximation coefficients of a
  34. % two-dimensional signal.A = APPCOEF2(C,S,'wname',N) computes the approximation coefficients at level N using the wavelet decomposition
  35. % structure [C,S] (see WAVEDEC2). 'wname' is a string containing the wavelet name.Level N must be an integer such that 0 <= N <= size(S,1)-2.
  36.    ca14=appcoef2(c2,l2,'sym4',4);%提取小波分解概貌系数

  37. %==========compute mean & var(求分解后的每个图象的均值和方差)==================
  38. %image x1's u & std
  39.    Csize1=size(ch11);
  40.    s1=0;
  41.    for i=1:Csize1(1)
  42.        for j=1:Csize1(2)
  43.            s1=s1+abs(ch11(i,j));%abs求绝对值
  44.        end
  45.    end
  46.    u1=(1/(Csize1(1)*Csize1(2)))*s1;

  47.    st1=0;
  48.    for i=1:Csize1(1)
  49.        for j=1:Csize1(2)
  50.            st1=st1+(abs(ch11(i,j))-u1)*(abs(ch11(i,j))-u1);
  51.        end
  52.    end
  53.    z1=sqrt((1/(Csize1(1)*Csize1(2)-1))*st1);
  54. %======================================================
  55.    Csize2=size(ch12);
  56.    s2=0;
  57.    for i=1:Csize2(1)
  58.        for j=1:Csize2(2)
  59.            s2=s2+abs(ch12(i,j));
  60.        end
  61.    end
  62.    u2=(1/(Csize2(1)*Csize2(2)))*s2;

  63.    st2=0;
  64.    for i=1:Csize2(1)
  65.        for j=1:Csize2(2)
  66.            st2=st2+(abs(ch12(i,j))-u2)*(abs(ch12(i,j))-u2);
  67.        end
  68.    end
  69.    z2=sqrt((1/(Csize2(1)*Csize2(2)-1))*st2);
  70. %===========================================================
  71.    Csize3=size(ch13);
  72.    s3=0;
  73.    for i=1:Csize3(1)
  74.        for j=1:Csize3(2)
  75.            s3=s3+abs(ch13(i,j));
  76.        end
  77.    end
  78.    u3=(1/(Csize3(1)*Csize3(2)))*s3;

  79.    st3=0;
  80.    for i=1:Csize3(1)
  81.        for j=1:Csize3(2)
  82.            st3=st3+(abs(ch13(i,j))-u3)*(abs(ch13(i,j))-u3);
  83.        end
  84.    end
  85.    z3=sqrt((1/(Csize3(1)*Csize3(2)-1))*st3);
  86. %================================================================
  87.    Csize3=size(ch14);
  88.    s3=0;
  89.    for i=1:Csize3(1)
  90.        for j=1:Csize3(2)
  91.            s3=s3+abs(ch14(i,j));
  92.        end
  93.    end
  94.    u4=(1/(Csize3(1)*Csize3(2)))*s3;

  95.    st3=0;
  96.    for i=1:Csize3(1)
  97.        for j=1:Csize3(2)
  98.            st3=st3+(abs(ch14(i,j))-u4)*(abs(ch14(i,j))-u4);
  99.        end
  100.    end
  101.    z4=sqrt((1/(Csize3(1)*Csize3(2)-1))*st3);
  102. %=================================================================
  103.    Csize4=size(cv11);
  104.    s4=0;
  105.    for i=1:Csize4(1)
  106.        for j=1:Csize4(2)
  107.           s4=s4+abs(cv11(i,j));
  108.        end
  109.    end
  110.    u5=(1/(Csize4(1)*Csize4(2)))*s4;

  111.    st4=0;
  112.    for i=1:Csize4(1)
  113.        for j=1:Csize4(2)
  114.            st4=st4+(abs(cv11(i,j))-u5)*(abs(cv11(i,j))-u5);
  115.        end
  116.    end
  117.    z5=sqrt((1/(Csize4(1)*Csize4(2)-1))*st4);
  118. %===============================================================
  119.    Csize5=size(cv12);
  120.    s5=0;
  121.    for i=1:Csize5(1)
  122.        for j=1:Csize5(2)
  123.            s5=s5+abs(cv12(i,j));
  124.        end
  125.    end
  126.    u6=(1/(Csize5(1)*Csize5(2)))*s5;

  127.    st5=0;
  128.    for i=1:Csize5(1)
  129.        for j=1:Csize5(2)
  130.            st5=st5+(abs(cv12(i,j))-u6)*(abs(cv12(i,j))-u6);
  131.        end
  132.    end
  133.    z6=sqrt((1/(Csize5(1)*Csize5(2)-1))*st5);
  134. %================================================================
  135.    Csize6=size(cv13);
  136.    s6=0;
  137.    for i=1:Csize6(1)
  138.        for j=1:Csize6(2)
  139.            s6=s6+abs(cv13(i,j));
  140.        end
  141.    end
  142.    u7=(1/(Csize6(1)*Csize6(2)))*s6;

  143.    st6=0;
  144.    for i=1:Csize6(1)
  145.        for j=1:Csize6(2)
  146.           st6=st6+(abs(cv13(i,j))-u7)*(abs(cv13(i,j))-u7);
  147.        end
  148.    end
  149.    z7=sqrt((1/(Csize6(1)*Csize6(2)-1))*st6);
  150. %==================================================================
  151.    Csize6=size(cv14);
  152.    s6=0;
  153.    for i=1:Csize6(1)
  154.        for j=1:Csize6(2)
  155.            s6=s6+abs(cv14(i,j));
  156.        end
  157.    end
  158.    u8=(1/(Csize6(1)*Csize6(2)))*s6;

  159.    st6=0;
  160.    for i=1:Csize6(1)
  161.        for j=1:Csize6(2)
  162.            st6=st6+(abs(cv14(i,j))-u8)*(abs(cv14(i,j))-u8);
  163.        end
  164.    end
  165.    z8=sqrt((1/(Csize6(1)*Csize6(2)-1))*st6);
  166. %==============================================================
  167.    Csize7=size(cd11);
  168.    s7=0;
  169.    for i=1:Csize7(1)
  170.        for j=1:Csize7(2)
  171.           s7=s7+abs(cd11(i,j));
  172.        end
  173.    end
  174.    u9=(1/(Csize7(1)*Csize7(2)))*s7;

  175.    st7=0;
  176.    for i=1:Csize7(1)
  177.        for j=1:Csize7(2)
  178.           st7=st7+(abs(cd11(i,j))-u9)*(abs(cd11(i,j))-u9);
  179.        end
  180.    end
  181.    z9=sqrt((1/(Csize7(1)*Csize7(2)-1))*st7);
  182. %====================================================================
  183.    Csize7=size(cd12);
  184.    s7=0;
  185.    for i=1:Csize7(1)
  186.        for j=1:Csize7(2)
  187.           s7=s7+abs(cd12(i,j));
  188.        end
  189.    end
  190.    u10=(1/(Csize7(1)*Csize7(2)))*s7;

  191.    st7=0;
  192.    for i=1:Csize7(1)
  193.       for j=1:Csize7(2)
  194.           st7=st7+(abs(cd12(i,j))-u10)*(abs(cd12(i,j))-u10);
  195.        end
  196.    end
  197.    z10=sqrt((1/(Csize7(1)*Csize7(2)-1))*st7);
  198. %=================================================
  199.    Csize7=size(cd13);
  200.    s7=0;
  201.    for i=1:Csize7(1)
  202.       for j=1:Csize7(2)
  203.           s7=s7+abs(cd13(i,j));
  204.        end
  205.    end
  206.    u11=(1/(Csize7(1)*Csize7(2)))*s7;

  207.    st7=0;
  208.    for i=1:Csize7(1)
  209.       for j=1:Csize7(2)
  210.          st7=st7+(abs(cd13(i,j))-u11)*(abs(cd13(i,j))-u11);
  211.       end
  212.    end
  213.    z11=sqrt((1/(Csize7(1)*Csize7(2)-1))*st7);
  214. %=================================================
  215.    Csize7=size(cd14);
  216.    s7=0;
  217.    for i=1:Csize7(1)
  218.        for j=1:Csize7(2)
  219.           s7=s7+abs(cd14(i,j));
  220.        end
  221.    end
  222.    u12=(1/(Csize7(1)*Csize7(2)))*s7;

  223.    st7=0;
  224.    for i=1:Csize7(1)
  225.        for j=1:Csize7(2)
  226.           st7=st7+(abs(cd14(i,j))-u12)*(abs(cd14(i,j))-u12);
  227.        end
  228.    end
  229.    z12=sqrt((1/(Csize7(1)*Csize7(2)-1))*st7);
  230. %=================================================
  231.    Csize7=size(ca14);
  232.    s7=0;
  233.    for i=1:Csize7(1)
  234.       for j=1:Csize7(2)
  235.           s7=s7+abs(ca14(i,j));
  236.       end
  237.    end
  238.    u13=(1/(Csize7(1)*Csize7(2)))*s7;

  239.    st7=0;
  240.    for i=1:Csize7(1)
  241.       for j=1:Csize7(2)
  242.          st7=st7+(abs(ca14(i,j))-u13)*(abs(ca14(i,j))-u13);
  243.       end
  244.    end
  245.    z13=sqrt((1/(Csize7(1)*Csize7(2)-1))*st7);

  246.    %semble feature vector========================================
  247.    % 应用准则函数把对分类影响不大的特征去除
  248.    feature_wl=[u1,z1,u2,z2,u3,z3,u4,z4,u5,z5,u6,z6,u7,z7,u8,z8,u9,z9,u10,z10,u11,z11,u12,z12,u13,z13];
  249.    %feature_wl=[u1,z1,u2,z2,u3,z3,u4,z4,u5,z5,u6,z6,u7,z7,u9,z9,u13,z13];
复制代码
发表于 2007-4-8 06:53 | 显示全部楼层
请问有没有关于时频分析
       的chirplet变换matlab程序呢?谢谢!
发表于 2007-4-8 13:24 | 显示全部楼层
请问楼主:
   我刚刚接触matlab和小波变换,   [c2,l2]=wavedec2(X1,4,'sym4');中对其参数有什么要求吗?为什么每次执行到这条语句的时候就出问题啊?
发表于 2007-4-11 14:38 | 显示全部楼层
楼主真慷慨,谢谢啦!请问有没有用小波神经网络进行图象识别的程序?
发表于 2007-4-12 11:32 | 显示全部楼层
有没有关于说话人识别中利用小波变换提取特征参数的程序,不胜感激,邮箱zbl@mail2.lut.cn
发表于 2007-4-17 16:22 | 显示全部楼层
LZ有关于小波奇异性检测方面的源程序么?
谢谢了:loveliness:
真是个慷慨的好LZ啊!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-12 01:24 , Processed in 0.065602 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表