OMP算法

function [A]=OMP(D,X,L); 
%=============================================
% Sparse coding of a group of signals based on a given 
% dictionary and specified number of atoms to use. 
% input arguments: 
%       D - the dictionary (its columns MUST be normalized).   字典,每列必须单位化
%       X - the signals to represent                           输入的信号,图像?
%       L - the max. number of coefficients for each signal.   稀疏度
% output arguments: 
%       A - sparse coefficient matrix.                         稀疏矩阵
%=============================================
[n,P]=size(X);
[n,K]=size(D);                                                
for k=1:1:P,                   
    a=[];
    x=X(:,k);                                               %选取输入信号的每一列
    residual=x;                                             %残差的初始值           
    indx=zeros(L,1);                                        %初始化索引矩阵  
    for j=1:1:L,
        proj=D'*residual;                                   %找到索引值,找出字典中的最大项
        [maxVal,pos]=max(abs(proj));
        pos=pos(1);                                          %增加索引值
        indx(j)=pos;
        a=pinv(D(:,indx(1:j)))*x;                            %根据投影关系利用最小二乘法计算信号在字典空间的投影
        residual=x-D(:,indx(1:j))*a;                         %
        if sum(residual.^2) < 1e-6    
            break;
        end
    end;
    temp=zeros(K,1);
    temp(indx(1:j))=a;%j=L了
    A(:,k)=sparse(temp);                                     %使用稀疏矩阵存储
end;
return;
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值