压缩感知入门matlab代码_第1页
压缩感知入门matlab代码_第2页
压缩感知入门matlab代码_第3页
压缩感知入门matlab代码_第4页
压缩感知入门matlab代码_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、30 eginnersCodeforCompressiveSensingAlejandroWeinsteinSeptember2009SparseSignalsintheTimeDomain1.1UsingaRandomSensingMatrixInthisfirstexamplewewillmeasureasignalthatissparseinthetimedomain.Wewillusearandomsensingmatrix,andwewillsolvetherecoveryproblemusingthel1-Magictoolbox.Weusethefollowingfunction

2、stogeneratethesignalsandthesensingmatrix:Listing1:Sparsesignalandrandommeasurementmatrix.functionf=getsparsefun(n,s)tmp=randperm(n);f=zeros(n,1);f(tmp(1:s)=randn(s,1);functionA=getArandom(n,m)A=sqrt(1/m)*randn(m,n);Thefollowingscriptusethesefunctionstogeneratethesignal,takethemeasurementsanddotherec

3、overy.Figure1showstheresult.Listing2:Example1.1234567891011121314151617181920212223242526272829%CSexample1Sensingmatrixphiisrandom.RepresentationbasisPsiistheRecoveringusingl1magic.2;s15*525=nsm%SignallengthSparsitylevelNumberofmeasurementsf=getsparsefun(n,s);A=getArandom(n,m);y=A*f;%Takethemeasurem

4、ents%Solveusingl1magic.path(path,./Optimization);x0=pinv(A)*y;%initialguess=ticxp=l1eqpd(x0,A,y,1e-3);tocnorm(f-xp)/norm(f)plot(f)holdonplot(xp,r.)legend(Original,Recovered)canonicalbasis.minenergy30 #TherecoverycanbemadebyusingCVXinsteadofl1-Magic.Justreplacelines19to24by3 -3.1111ii1I111OriginRecov

5、alered-111111I111|210-1-250100150200250300350400450500Figure1:Script1results.Listing3:UsingCVXfortherecovery.%SolveusingCVX.cvxbeginvariablexp(n);minimize(norm(xp,1);subjecttoA*xp=y;cvxend1.2UsingaFourierSensingMatrixNowwearegoingtorepeatthesameexperiment,butusingasamplingmatrixbasedontheFourierbasi

6、s.Wegeneratethemeasurementmatrixwiththefollowingfunction:Listing4:Fourierbasedmeasurementmatrix.functionA=getAfourier(n,m)tmp=randperm(n);phi=inv(fft(eye(n);A=phi(tmp(1:m/2),:);A=real(A);imag(A);Inordertorecoverthesignalusingl1-magic,nowweneedtousethefunctionl1qc_logbarrierinsteadofl1eq_pd.Ontheothe

7、rhand,thereisnoneedtochangeanythingwhensolvingtheproblemwithCVX.SinceingeneralissimplerandclearertouseCVX,weonlyusethisapproachinthefollowingexamples.SparseSignalintheFrequencyDomainLetstrynowwithasignalsparseinthefrequencydomain.Wegeneratethesignalas:Listing5:Sparsesignalinthefrequencydomain.0:n-1;

8、cos(2*pi/256*t)+cos(2*pi/128*t); 1234567891011Figure2showstheresult.Asexpected,therecoveryisexact.Letsmodifyoursignalslightly,byreplacingoneofthecosinebyasine:LetssolvewitharandomsensingmatrixandCVX.Noticethatnowweneedtospecifytherepresentationbasis(seeline5):Listing6:RandommeasurementsandCVXrecover

9、y.A=getArandom(n,m);y=A*f;%SolveusingCVX.Psi=inv(fft(eye(n);cvxbeginvariablexp(n);minimize(norm(xp,1);subjecttoA*Psi*xp=y;cvxendFigure2:Recoveryofafrequencydomainsparsesignal.Listing7:Sparsesignalinthefrequencydomain.t=0:n-1;f=cos(2*pi/256*t)+sin(2*pi/128*t);Figure3showstheresult.Evidentlythereissom

10、ethingwrong.TheproblemisthatnowtheFouriercoefficientshaveanimaginarycomponent,butCVXissearchingforarealx.Thesolutioniseasy,wejustneedtotellCVXtoconsideracomplexx:Listing8:Sparsesignalinthefrequencydomain.%SolveusingCVX.Psi=inv(fft(eye(n);cvxbeginvariablexp(n)complex;%WeneedtotellCVXthatxpiscomplex!m

11、inimize(norm(xp,1);subjecttoA*Psi*xp=y;cvxendFigure4showstheresult.Nowtherecoveryisexact.Wecanalsotrywithahighersparsitylevel.Thefollowingscriptcreateasignalbyaddingsixsinusoidswithrandomperiod,amplitudeandphases.Noticethattheperiodsarechosenfromthevector163264128256512.Figure5showstheresult.Onceaga

12、in,therecoveryisexact.Listing9:Signalmadeof6randomsinuoids.s=6;amp=rand(s,1);%amplitudesperiods=163264128256512;4tmp=randperm(length(periods);freq=(2*pi./round(periods(tmp(1:s);%frequenciesphases=2*pi*rnd(s,1);f=zeros(n,1);t=0:n-1;fork=1:s,f=f+amp(k)*cos(freq(k)*t+phases(k);endWenowreplacetheperiods

13、weareusingby183264128256512.Noticethattheonlydifferenceisthatnowthesmallestperiodis18insteadof16.Figure6showstheresult.Nowtheresultisnotexact.Thereasonforthisisthatnowthesignalisnotreallysparse,sinceoneoftheperiodsisnotanintegermultipleofthesignallength.AcknowledgmentsThankstoDr.MichaelWakinandBorhanSanandajiforhelpingmetosolvesomeoftheissuesIhadwiththecode.1Ifthesignalissparseinthetimedomain,=Identitymatrix,thatswhywedidntspecifyinsection1.Figure4:SuccessfullyrecoveryaftertellingCVXtouseacomple

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论