基于GA和MP的信号稀疏分解matlab程序.docx
《基于GA和MP的信号稀疏分解matlab程序.docx》由会员分享,可在线阅读,更多相关《基于GA和MP的信号稀疏分解matlab程序.docx(6页珍藏版)》请在冰豆网上搜索。
基于GA和MP的信号稀疏分解
%%MATLABscriptforMPalgorithmbasedonFFT
%
%
%********************Preparationpart*****************************
%
%**************************part1:
imputsignal***************************Im=wavread('FEM');
Im=Im';
%****************************part2:
set parameters***********************f1=50;
f2=160;fs=200;
iterative_number=100; %thematchingpursuitprocessingiterativenumber[a,N]=size(Im); %thelongthofsignalandthelongthofatoms;Na_base=2; %scale:
thescaleisdeterminedbyaandj;
j_min=0;j_max=log2(N);
u_base=1/2; %thetransmissionordisplacementushoulddeterminedasfollowingv_base=pi; %thefrequencyv
k_min=0;
w_base=pi/6; %thephase wi_min=0;
i_max=12;
%%************************initialization ********************************signal=Im;
signal_reconstruct=zeros(1,N);signal_r=Im;
%***************wipeoffthedirectcurrentvector*************************
signal_reconstruct=(1/N)*sum(signal);signal_r=signal-signal_reconstruct;
%*********************startcalculation*********************************forn=1:
iterative_number
%********thefollowingprogramusesonesubroutinetoselectthebestatom**************
[proj,scale,translation,freq,phase]=gas(signal_r,N,a_base,j_min,j_max,u_base,p_min,v_base,k_min,w_base,i_min,i_max);
%******reconstructthebestatomfromtheparametersgotbyabovesubroutine*********t=0:
N-1;
t=(t-translation)/scale;
g=(1/sqrt(scale))*exp(-pi*t.*t).*cos(freq*t+phase);g=g./sqrt(sum(g.*g)); %normalizatiomtheatom
%***********reconstruct signalandrenewtheresidual**********************signal_reconstruct=signal_reconstruct+proj*g;
signal_r=signal_r-proj*g;
%*************************thefigureofresult************************subplot(221);
plot(signal); %originalsiganlsubplot(222);
plot(g); %theatomsubplot(223);
plot(signal_r); %theresidualsubplot(224);
plot(signal_reconstruct); %reconstructsignalend
%******************endoffile*************************************function
[proj,scale,translation,freq,phase]=gas(signal_r,N,a_base,j_min,j_max,u_base,p_min,v_base,k_min,w_base,i_min,i_max)
%thissubroutineistoselectinthedictionarythebestatomsuitedthesignalortheresidualofthesignal
%thesearchingmethodusedisGeneticAlgorithm(GA).
%thefollowingparametersareusedinGA
% n:
numberofChromosomes
% Ngen:
thenumberofgeneration
% vec:
thesolutionforoneatom
% v
(1):
thescale
% v
(2):
locationortranslation
% v(3):
frequency
% v(4):
phase
%Geneticalgorithm:
INITIALIZATION初始化
%proj_trans:
todeterminewhichprojectionisbiggest
%n:
numberofchromosomes
%Ngen:
thenumberofgeneration
%**********************setparrameter***********************************n=21;
Ngen=30;
pool=zeros(4,n);sig=[1
1
1
1];
proj_trans=zeros(1,n);res=ones(1,n);proj=0;
bi=ones(4,1); %bi:
lowerboundsbs=ones(4,1); %bs:
upperbounds
bi
(1)=j_min;bi
(2)=p_min;bi(3)=k_min;bi(4)=i_min;
bs
(1)=j_max;bs
(2)=N;
bs(3)=N;
bs(4)=i_max;
og=ones(4,n); %og(i,:
):
vectorofni-genesng=ones(4,n); %ng:
newgenerationvector
%********************createtheinitialpopulation***************************og(1,:
)=round((bs
(1)-bi
(1))*rand(1,n)+bi
(1));
og(2,:
)=round((bs
(2)-bi
(2))*rand(1,n)+bi
(2));
og(3,:
)=round((bs(3)-bi(3))*rand(1,n)+bi(3));
og(4,:
)=round((bs(4)-bi(4))*rand(1,n)+bi(4));
%******************themainpartof Geneticalgorithm****************forc=1:
Ngen
ford=1:
n
s=a_base^og(1,d);u=og(2,d);v=og(3,d)*(1/s)*v_base;
w=og(4,d)*w_base;t=0:
N-1;
t=(t-u)/s;
g=(1/sqrt(s))*exp(-pi*t.*t).*cos(v*t+w);g=g/sqrt(sum(g.*g));proj_trans(d)=sum(signal_r.*g);res(d)=abs(proj_trans(d));
end
%********placethebestatom(biggestprojectioninthefirst position)*********
[best,e]=max(res);ng(:
1)=og(:
e);
og(:
e)=og(:
n);
og(:
n)=ng(:
1);temp_proj=proj_trans(e);temp_res=res(e);proj_trans(e)=proj_trans(n);proj_trans(n)=temp_proj;
res(e)=res(n);res(n)=temp_res;
%**************competitionbetweentheadjacentatoms***********************ford=2:
2:
n-1
[best,e]=max(res(d-1:
d));
pool(:
d/2)=og(:
d-rem(e,2));end;
%*****************creationofthepoolforcrossover ********************ford=1:
(n-1)/2
f=ceil((n-1)/2*rand);Inter=round(rand(4,1));
ng(:
d+1)=pool(:
d).*Inter+pool(:
f).*(1-Inter);
end
%*****************Mutationsofthewinner *********************sigm=sig(:
ones(n-((n-1)/2+1),1));
ngm=ng(:
1);
ngm=ngm(:
ones(n-((n-1)/2+1),1));
ng(:
(n-1)/2+2:
n)=round(ngm+(rand(4,n-((n-1)/2+1))-0.5).*sigm);
%*************************boundingintothelimits**********************forl=1:
4
whilemax(ng(l,:
))>bs(l)
[rw,lw]=max(ng(l,:
));ng(l,lw)=bs(l);
end
whilemin(ng(l,:
))end
end
[rw,lw]=min(ng(l,:
));ng(l,lw)=bi(l);
og=ng;
%*******************stable or not?
*********************************nog=og(:
1);
nog=nog(:
ones(1,n));nog=abs(