Bootstrap

压缩感知之常用测量矩阵及matlab代码


前言

  观测矩阵的设计是压缩感知的第二步,在这里给出常用的测量矩阵matlab代码,供大家查找使用。代码内容参考自以下网站,并针对其中个别的代码进行了修改,想探究其原理的可进入此网站查找~

https://blog.csdn.net/jbb0523/article/details/44700735


一、测量矩阵是什么?

  测量矩阵用来使人们可以看到由仪器所获得的观测值 y y y。其具体表达式为: y = Φ x y=\varPhi x y=Φx其中, x x x是原始信号, y y y为观察的信号。从原始信号中可以观察到多少信号,就是由测量矩阵决定的,因此其会涉及到采样率的概念。通常的采样率概念定义为测量矩阵的行数/列数,即 M / N M/N M/N,大家有兴趣的可以查阅资料进行学习~

二、常用的测量矩阵及其matlab代码

1、随机高斯测量矩阵

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、随机伯努利测量矩阵

function [ Phi ] = BernoulliMtx( M,N )
%BernoulliMtx Summary of this function goes here
%   Generate Bernoulli matrix 
%   M -- RowNumber
%   N -- ColumnNumber
%   Phi -- The Bernoulli matrix

    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);    %按照公式来看应该有这句
end

3、部分哈达玛测量矩阵

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、部分傅里叶测量矩阵

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、稀疏随机测量矩阵

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、拓普利兹测量矩阵

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

7、循环测量矩阵

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

总结

  以上就是此节要展示的代码内容。自己在学习压缩感知的过程中查阅过很多资料,也测试过很多代码,这里的代码入股不亏。如果代码仍和其原理有所偏差,大家也可以根据原理自行进行修改~

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;