日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

常见测量矩阵的MATLAB实现

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 常见测量矩阵的MATLAB实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

常見測量矩陣的MATLAB實現

? ? ? ??下面以文獻【吳赟.壓縮感知測量矩陣的研究[D]. 西安電子科技大學碩士學位論文,2012】為依據,給出文獻中2.2節內容所述的六種測量矩陣MATLAB實現代碼,僅為一種參考實現方式,還未驗證其正確性。

1、高斯矩陣


? ? ? ??以下代碼生成的高斯矩陣方差為1,若為改為1/M,只須將除以根號M即可。

[plain]?view plaincopy
  • function?[?Phi?]?=?GaussMtx(?M,N?)??
  • %GaussMtx?Summary?of?this?function?goes?here??
  • %???Generate?Bernoulli?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???Phi?--?The?Gauss?matrix??
  • ??
  • %%?Generate?Gauss?matrix?????
  • ????Phi?=?randn(M,N);??
  • ????%Phi?=?Phi/sqrt(M);??
  • end??
  • 2、伯努利矩陣



    ? ? ? ??以下代碼是按式(2-8)生成的伯努利矩陣,若要按式(2-9)生成則需使用后半部分注釋掉的代碼即可。注意代碼中用到了MATLAB自帶的randi函數,若你的MATLAB版本較低,可能要用randint函數代替,后面若用到此函數則一樣要注意這一點。

    [plain]?view plaincopy
  • function?[?Phi?]?=?BernoulliMtx(?M,N?)??
  • %BernoulliMtx?Summary?of?this?function?goes?here??
  • %???Generate?Bernoulli?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???Phi?--?The?Bernoulli?matrix??
  • ??
  • %%?(1)Generate?Bernoulli?matrix(The?first?kind)??
  • %?1--P=0.5???-1--P=0.5??
  • ????Phi?=?randi([0,1],M,N);%If?your?MATLAB?version?is?too?low,please?use?randint?instead??
  • ????Phi(Phi==0)?=?-1;??
  • ????%Phi?=?Phi/sqrt(M);??
  • %?%%?(2)Generate?Bernoulli?matrix(The?second?kind)??
  • %?%?1--P=1/6???-1--P=1/6??0--2/3??
  • %?????Phi?=?randi([-1,4],M,N);%If?your?MATLAB?version?is?too?low,please?use?randint?instead??
  • %?????Phi(Phi==2)?=?0;%P=1/6??
  • %?????Phi(Phi==3)?=?0;%P=1/6??
  • %?????Phi(Phi==4)?=?0;%P=1/6??
  • %?????%Phi?=?Phi*sqrt(3/M);??
  • end??
  • 3、部分哈達瑪矩陣


    ? ? ? ??由于MATLAB自帶的函數hadamard參數有限制,所以程序中首先計算滿足要求的參數L,需要注意的是,hadamard參數并不像文獻中所述僅為2的整數次冪,而是12的整數倍或20的整數倍或2的整數次冪,詳情在MATLAB查看hadamard的help文件。

    [plain]?view plaincopy
  • function?[?Phi?]?=?PartHadamardMtx(?M,N?)??
  • %PartHadamardMtx?Summary?of?this?function?goes?here??
  • %???Generate?part?Hadamard?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???Phi?--?The?part?Hadamard?matrix??
  • ??
  • %%?parameter?initialization??
  • %Because?the?MATLAB?function?hadamard?handles?only?the?cases?where?n,?n/12,??
  • %or?n/20?is?a?power?of?2??
  • ????L_t?=?max(M,N);%Maybe?L_t?does?not?meet?requirement?of?function?hadamard??
  • ????L_t1?=?(12?-?mod(L_t,12))?+?L_t;??
  • ????L_t2?=?(20?-?mod(L_t,20))?+?L_t;???
  • ????L_t3?=?2^ceil(log2(L_t));??
  • ????L?=?min([L_t1,L_t2,L_t3]);%Get?the?minimum?L??
  • %%?Generate?part?Hadamard?matrix?????
  • ????Phi?=?[];??
  • ????Phi_t?=?hadamard(L);??
  • ????RowIndex?=?randperm(L);??
  • ????Phi_t_r?=?Phi_t(RowIndex(1:M),:);??
  • ????ColIndex?=?randperm(L);??
  • ????Phi?=?Phi_t_r(:,ColIndex(1:N));??
  • end??
  • 4、部分傅里葉矩陣


    ? ? ? ??以下代碼生成的是部分傅里葉矩陣,這里要提的一點是,有關“歸一化”的概念在網上說法不一,一種說法是向量除以向量各項之和,另一種說法是向量除以向量的2范數(各項平方之和再開方),這里采用后者。

    [plain]?view plaincopy
  • function?[?Phi?]?=?PartFourierMtx(?M,N?)??
  • %PartFourierMtx?Summary?of?this?function?goes?here??
  • %???Generate?part?Fourier?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???Phi?--?The?part?Fourier?matrix??
  • ??
  • %% Generate?part?Fourier?matrix?????
  • ????Phi_t?=?fft(eye(N,N))/sqrt(N);%Fourier?matrix??
  • ????RowIndex?=?randperm(N);??
  • ????Phi?=?Phi_t(RowIndex(1:M),:);%Select?M?rows?randomly??
  • ????%normalization??
  • ????for?ii?=?1:N??
  • ????????Phi(:,ii)?=?Phi(:,ii)/norm(Phi(:,ii));??
  • ????end??
  • end??
  • 5、稀疏隨機矩陣


    [plain]?view plaincopy
  • function?[?Phi?]?=?SparseRandomMtx(?M,N,d?)??
  • %SparseRandomMtx?Summary?of?this?function?goes?here??
  • %???Generate?SparseRandom?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???d?--?The?number?of?'1'?in?every?column,d<M???
  • %???Phi?--?The?SparseRandom?matrix??
  • ??
  • %%?Generate?SparseRandom?matrix?????
  • ????Phi?=?zeros(M,N);??
  • ????for?ii?=?1:N??
  • ????????ColIdx?=?randperm(M);??
  • ????????Phi(ColIdx(1:d),ii)?=?1;??
  • ????end??
  • end??
  • 6、托普利茲矩陣和循環矩陣


    ? ? ? ??這里先給出托普利茲矩陣,文中說經過M次循環,這里直接利用MATLAB自帶函數生成一個托普利茲方陣再取前M行。

    [plain]?view plaincopy
  • function?[?Phi?]?=?ToeplitzMtx(?M,N?)??
  • %ToeplitzMtx?Summary?of?this?function?goes?here??
  • %???Generate?Toeplitz?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???Phi?--?The?Toeplitz?matrix??
  • ??
  • %%?Generate?a?random?vector??
  • %?????%(1)Gauss??
  • %?????u?=?randn(1,2*N-1);??
  • ????%(2)Bernoulli??
  • ????u?=?randi([0,1],1,2*N-1);??
  • ????u(u==0)?=?-1;??
  • %%?Generate?Toeplitz?matrix?????
  • ????Phi_t?=?toeplitz(u(N:end),fliplr(u(1:N)));??
  • ????Phi?=?Phi_t(1:M,:);??
  • end??
  • ? ? ? ??下面是循環矩陣,仍然利用MATLAB自帶函數生成。

    [plain]?view plaincopy
  • function?[?Phi?]?=?CirculantMtx(?M,N?)??
  • %CirculantMtx?Summary?of?this?function?goes?here??
  • %???Generate?Circulant?matrix???
  • %???M?--?RowNumber??
  • %???N?--?ColumnNumber??
  • %???Phi?--?The?Circulant?matrix??
  • ??
  • %%?Generate?a?random?vector??
  • %?????%(1)Gauss??
  • %?????u?=?randn(1,N);??
  • ????%(2)Bernoulli??
  • ????u?=?randi([0,1],1,N);??
  • ????u(u==0)?=?-1;??
  • %%?Generate?Circulant?matrix?????
  • ????Phi_t?=?toeplitz(circshift(u,[1,1]),fliplr(u(1:N)));??
  • ????Phi?=?Phi_t(1:M,:);??
  • end??
  • ? ? ? ??以上都是采用MATLAB自帶的toeplitz函數,這需要首先生成一個隨機向量,而托普利茲矩陣和循環矩陣的區別也就在于這個隨機向量的結構不同,注意代碼中有關toeplitz函數的兩個輸入參數好好體會即可。

    總結

    以上是生活随笔為你收集整理的常见测量矩阵的MATLAB实现的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。