comparison util/classes/@dictionary/dictionary.m @ 160:e3035d45d014 danieleb

Added support classes
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Wed, 31 Aug 2011 10:53:10 +0100
parents
children 8fc38e8df8c6
comparison
equal deleted inserted replaced
159:23763c5fbda5 160:e3035d45d014
1 classdef dictionary
2 %% Dictionary for sparse representation
3 properties
4 phi %Matrix containing the dictionary
5 len %Length of basis functions
6 nAtoms %Number of basis function
7 name %String containing the matrix ensemble from which the dictionary is drawn
8 end
9 properties (Dependent = true)
10 redundancy %Redundancy of the dictionary: nAtoms/len
11 coherence %Maximum inner product of different basis
12 isNormalised %True if the atoms have unit norm
13 rank %rank of the dictionary
14 end
15
16 methods
17 %% Constructor
18 function obj = dictionary(phi,len,nAtoms)
19 % obj = dictionary(phi,len,nAtoms)
20 % INPUTS:
21 % - phi: either a string specifying a matrix ensamble or a
22 % matrix defining an explicit dictionary
23 % - len: length of the atoms (only for implicit dictionaries)
24 % - nAtoms: number of atoms (only for implicit dictionaries)
25 if nargin
26 if ~ischar(phi)
27 [obj.len obj.nAtoms] = size(phi);
28 obj.phi = phi;
29 obj.name = 'explicit';
30 else
31 switch lower(phi)
32 case 'dct'
33 obj.phi = dctmatrix(len,nAtoms);
34 case 'grassmanian'
35 obj.phi = grassmanian(len,nAtoms);
36 otherwise
37 obj.phi = MatrixEnsemble(len,nAtoms,phi);
38 end
39 obj.len = len;
40 obj.nAtoms = nAtoms;
41 obj.name = lower(phi);
42 end
43 end
44 end
45
46 %% Dependent properties
47 function redundancy = get.redundancy(obj)
48 redundancy = obj.nAtoms/obj.len;
49 end
50 function coherence = get.coherence(obj)
51 obj.phi = normcol(obj.phi);
52 G = obj.phi'*obj.phi;
53 G = G - eye(size(G));
54 coherence = max(abs(G(:)));
55 end
56 function isNormalised = get.isNormalised(obj)
57 isNormalised = norm(sum(conj(obj.phi).*obj.phi) - ...
58 ones(1,obj.nAtoms))<1e-9;
59 end
60 function r = get.rank(obj)
61 r = rank(obj.phi);
62 end
63 %% Operations
64 function obj = normalize(obj)
65 obj.phi = normcol(obj.phi);
66 end
67
68 %% Visualization
69 function image(obj)
70 %Image of the dictionary
71 if isreal(obj.phi)
72 imagesc(obj.phi);
73 title('Dictionary');
74 xlabel('Atom number');
75 else
76 subplot(2,1,1)
77 imagesc(real(obj.phi));
78 title('Real');
79 xlabel('Atom number');
80 subplot(2,1,2)
81 imagesc(imag(obj.phi));
82 title('Imaginary');
83 xlabel('Atom number');
84 end
85 end
86 function imagegram(obj)
87 G = obj.phi'*obj.phi;
88 imagesc(G);
89 title('Gram Matrix')
90 end
91 function plot(obj,n)
92 %Plot of the n-th basis
93 if isreal(obj.phi)
94 plot(obj.phi(:,n));
95 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2))]);
96 else
97 subplot(2,1,1)
98 plot(real(obj.phi(:,n)));
99 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2)) ' - Real']);
100 subplot(2,1,2)
101 plot(imag(obj.phi(:,n)));
102 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2)) ' - Imaginary']);
103 end
104 end
105
106 function movie(obj)
107 %Movie of the basis
108 for i=1:size(obj.phi,2)
109 obj.plot(i);
110 pause(1/25);
111 end
112 end
113 end
114 end