壓縮感知入門matlab代碼_第1頁
壓縮感知入門matlab代碼_第2頁
壓縮感知入門matlab代碼_第3頁
壓縮感知入門matlab代碼_第4頁
壓縮感知入門matlab代碼_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論