-
Notifications
You must be signed in to change notification settings - Fork 2
/
SOMP.m
39 lines (35 loc) · 1.02 KB
/
SOMP.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function [x]=SOMP(D,y,K);
%=============================================
% 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).
% y - the signals to represent
% K - the max. number of coefficients for each signal.
% output arguments:
% x - sparse coefficient matrix.
% author: Cheng Wang, Hunan University
%=============================================
[m,l]=size(y);
[m,n]=size(D);
x = zeros(n,l);
%this algorithm reduces to standard orthogonal persuit when l=1;
residual = y;
index = [];
t = 1;
for t = 1:1:K,
proj = D'*residual;
% proj_t = sum(abs(proj),2);%1·¶Êý
proj_t = max(proj',[],1);%ÿÁеÄ×î´óÖµ
if max(proj_t)> 0.0001
pos=find(proj_t==max(proj_t));
pos=pos(1);
index(t)=pos;
x_temp=pinv(D(:,index))*y;
residual=y-D(:,index)*x_temp;
end
end
if (length(index)>0)
x(index,:)=x_temp;
end
return;