资源描述:
《压缩感知入门matlab代码.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、BeginnersCodeforCompressiveSensingAlejandroWeinsteinSeptember20091SparseSignalsintheTimeDomain1.1UsingaRandomSensingMatrixInthis¯rstexamplewewillmeasureasignalthatissparseinthetimedomain.Wewillusearandomsensingmatrix,andwewillsolvetherecoveryproblemusingthe
2、l1-Magictoolbox.Weusethefollowingfunctionstogeneratethesignalsandthesensingmatrix: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);
3、Thefollowingscriptusethesefunctionstogeneratethesignal,takethemeasurementsanddotherecovery.Figure1showstheresult.Listing2:Example1.1%CSexample12%Sensingmatrixphiisrandom.3%RepresentationbasisPsiisthecanonicalbasis.4%Recoveringusingl1magic.56clc7clearall8clo
4、seall910n=512;%Signallength11s=25;%Sparsitylevel12m=5¤s;%Numberofmeasurements1314f=getsparsefun(n,s);15A=getArandom(n,m);1617y=A¤f;%Takethemeasurements1819%Solveusingl1magic.20path(path,'./Optimization');21x0=pinv(A)¤y;%initialguess=minenergy22tic23xp=l1eqp
5、d(x0,A,[],y,1e¡3);24toc2526norm(f¡xp)/norm(f)27plot(f)28holdon29plot(xp,'r.')30legend('Original','Recovered')TherecoverycanbemadebyusingCVXinsteadofl1-Magic.Justreplacelines19to24by13OriginalRecovered210−1−2−350100150200250300350400450500Figure1:Script1resu
6、lts.Listing3:UsingCVXfortherecovery.%SolveusingCVX.cvxbeginvariablexp(n);minimize(norm(xp,1));subjecttoA¤xp==y;cvxend1.2UsingaFourierSensingMatrixNowwearegoingtorepeatthesameexperiment,butusingasamplingmatrixbasedontheFourierbasis.Wegeneratethemeasurementma
7、trixwiththefollowingfunction: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_logbarrierinstead
8、ofl1eq_pd.Ontheotherhand,thereisnoneedtochangeanythingwhensolvingtheproblemwithCVX.SinceingeneralissimplerandclearertouseCVX,weonlyusethisapproachinthefollowingexamples.2SparseSignalintheFrequencyDomai