File: comp_dst.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 (103 lines) | stat: -rw-r--r-- 2,595 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
function c = comp_dst(f,type)
%-*- texinfo -*-
%@deftypefn {Function} comp_dst
%@verbatim
%COMP_DST Calculates DST
%   Input parameters:
%         f     : Input data.
%         type  : DST version.
%
%@end verbatim
%@strong{Url}: @url{http://ltfat.github.io/doc/comp/comp_dst.html}
%@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/>.


[L,W] = size(f);


switch type
   case 1
      c=zeros(L,W,assert_classname(f));

      s1=dft([zeros(1,W,assert_classname(f));...
	           f;...
	           zeros(1,W,assert_classname(f));...
	           -flipud(f)]);


      % This could be done by a repmat instead.
      for w=1:W
         c(:,w)=s1(2:L+1,w)-s1(2*L+2:-1:L+3,w);
      end;

      c=c*1i/2;
   case 2
      c=zeros(L,W,assert_classname(f));

      m1=1/sqrt(2)*exp(-(1:L)*pi*i/(2*L)).';
      m1(L)=-i;
  
      m2=-1/sqrt(2)*exp((1:L-1)*pi*i/(2*L)).';

      s1=i*fft([f;-flipud(f)])/sqrt(L)/2;

      % This could be done by a repmat instead.
      for w=1:W
        c(:,w)=s1(2:L+1,w).*m1+[s1(2*L:-1:L+2,w).*m2;0];
      end;
   case 3
      c=zeros(2*L,W,assert_classname(f));

      m1=1/sqrt(2)*exp((1:L)*pi*i/(2*L)).';
      m1(L)=i;

      m2=-1/sqrt(2)*exp(-(L-1:-1:1)*pi*i/(2*L)).';

      for w=1:W
        c(:,w)=[0;m1.*f(:,w);m2.*f(L-1:-1:1,w)];
      end;

      c=-sqrt(L)*2*i*ifft(c);
      c=c(1:L,:);
   case 4
      s1=zeros(2*L,W,assert_classname(f));
      c=zeros(L,W,assert_classname(f));

      m1=1/sqrt(2)*exp(-(0:L-1)*pi*i/(2*L)).';
      m2=-1/sqrt(2)*exp((1:L)*pi*i/(2*L)).';

      for w=1:W
        s1(:,w)=[m1.*f(:,w);flipud(m2).*f(L:-1:1,w)];
      end;

      s1=i*exp(-pi*i/(4*L))*fft(s1)/sqrt(2*L);

      % This could be done by a repmat instead.
      for w=1:W
        c(:,w)=s1(1:L,w).*m1+s1(2*L:-1:L+1,w).*m2;
      end;
   otherwise
      error('%s: Type not supported.',upper(mfilename));
end


if isreal(f)
   c=real(c);
end;