File: matrix2latticetype.m

package info (click to toggle)
octave-ltfat 2.3.1%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,712 kB
  • sloc: ansic: 30,379; cpp: 8,808; java: 1,499; objc: 345; makefile: 248; xml: 182; python: 124; sh: 18; javascript: 12
file content (145 lines) | stat: -rw-r--r-- 3,979 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
function [a,M,lt] = matrix2latticetype(L,V);
%-*- texinfo -*-
%@deftypefn {Function} matrix2latticetype
%@verbatim
%MATRIX2LATTICETYPE  Convert matrix form to standard lattice description
%   Usage: [a,M,lt] = matrix2latticetype(L,V);
%
%   [a,M,lt]=MATRIX2LATTICETYPE(L,V) converts a 2x2 integer matrix
%   description into the standard description of a lattice using the a,
%   M and lt. The conversion is only valid for the specified transform
%   length L.
%
%   The lattice type lt is a 1 x2 vector [lt_1,lt_2] denoting an
%   irreducible fraction lt_1/lt_2. This fraction describes the distance
%   in frequency (counted in frequency channels) that each coefficient is
%   offset when moving in time by the time-shift of a. Some examples:
%   lt=[0 1] defines a square lattice, lt=[1 2] defines the quinqux
%   (almost hexagonal) lattice, lt=[1 3] describes a lattice with a
%   1/3 frequency offset for each time shift and so forth.
%
%   An example:
%
%     [a,M,lt] = matrix2latticetype(120,[10 0; 5 10])
%
%   Coefficient layout:
%   -------------------
%
%   The following code generates plots which show the coefficient layout
%   and enumeration of the first 4 lattices in the time-frequecy plane:
%
%     a=6;
%     M=6;
%     L=36;
%     b=L/M;
%     N=L/a;
%     cw=3;
%     ftz=12;
%     
%     [x,y]=meshgrid(a*(0:N-1),b*(0:M-1));
%
%     lt1=[0 1 1 2];
%     lt2=[1 2 3 3];
%
%     for fignum=1:4
%       subplot(2,2,fignum);
%       z=y;
%       if lt2(fignum)>0
%         z=z+mod(lt1(fignum)*x/lt2(fignum),b);
%       end;
%       for ii=1:M*N
%         text(x(ii)-cw/4,z(ii),sprintf('%2.0i',ii),'Fontsize',ftz);
%         rectangle('Curvature',[1 1], 'Position',[x(ii)-cw/2,z(ii)-cw/2,cw,cw]);
%       end;
%       axis([-cw L -cw L]);
%       axis('square');
%       title(sprintf('lt=[%i %i]',lt1(fignum),lt2(fignum)),'Fontsize',ftz);
%     end;
%
%@end verbatim
%@strong{Url}: @url{http://ltfat.github.io/doc/gabor/matrix2latticetype.html}
%@seealso{latticetype2matrix}
%@end deftypefn

% Copyright (C) 2005-2016 Peter L. Soendergaard <peter@sonderport.dk>.
% This file is part of LTFAT version 2.3.1
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

% The Hermite normal form code was originally written by Arno J. van Leest, 1999.
% Positive determinant by Peter L. Soendergaard, 2004.
% Unique form by Christoph Wiesmeyr, 2012

if nargin~=2
  error('%s: Wrong number of input arguments.',upper(mfilename));
end;

% Check if matrix has correct size.
if size(V,1)~=2 || size(V,2)~=2
  error('%s: V must be a 2x2 matrix.',upper(mfilename));
end;

% Integer values
if norm(mod(V,1))~=0
  error('%s: V must have all integer values.',upper(mfilename));
end;

% Convert to Arnos normal form.
gcd1=gcd(V(1,1),V(1,2));
gcd2=gcd(V(2,1),V(2,2));

A=zeros(2);
A(1,:)=V(1,:)/gcd1;
A(2,:)=V(2,:)/gcd2;

D = det(A);

% Exchange vectors if determinant is negative.
if D<0
  D=-D;
  A=fliplr(A);
end;

[g,h0,h1] = gcd(A(1,1),A(1,2));

x = A(2,:)*[h0;h1];

x = mod(x,D);

% Octave does not automatically round the double division to integer
% numbers, and this causes confusion later in the GCD computations. 
a = gcd1;
b = round(D*gcd2);
s = round(x*gcd2);

% compute nabs format of <a,s>
b1 = gcd(s*lcm(a,L)/a,L);
[a,k1] = gcd(a,L);
s = k1*s;

% update b
b = gcd(b,gcd(b1,L));

% update s
s = mod(s,b);

% conversion from nabs to latticetype
M=L/b;

k=gcd(s,b);
lt=[s/k b/k];