## [77a22a]: nonstatgab / unsdgtreal.m  Maximize  Restore  History

### 136 lines (121 with data), 4.8 kB

 ``` 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``` ```function [c,Ls] = unsdgtreal(f,g,a,M) %UNSDGTREAL Uniform non-stationary Discrete Gabor transform % Usage: c=unsdgtreal(f,g,a,M); % [c,Ls]=unsdgtreal(f,g,a,M); % % Input parameters: % f : Input signal. % g : Cell array of window functions. % a : Vector of time positions of windows. % M : Vector of numbers of frequency channels. % Output parameters: % c : Cell array of coefficients. % Ls : Length of input signal. % % `unsdgtreal(f,g,a,M)` computes the nonstationary Gabor coefficients of the % input signal *f*. The signal *f* can be a multichannel signal, given in % the form of a 2D matrix of size \$Ls \times W\$, with *Ls* the signal % length and *W* the number of signal channels. % % As opposed to |nsdgt|_ only the coefficients of the positive frequencies % of the output are returned. `unsdgtreal` will refuse to work for complex % valued input signals. % % The non-stationary Gabor theory extends standard Gabor theory by % enabling the evolution of the window over time. It is therefore % necessary to specify a set of windows instead of a single window. This % is done by using a cell array for *g*. In this cell array, the n'th % element `g{n}` is a row vector specifying the n'th window. The % uniformity means that the number of channels is not allowed to vary over % time. % % The resulting coefficients is stored as a \$M/2+1 \times N \times W\$ % array. `c(m,n,l)` is thus the value of the coefficient for time index *n*, % frequency index *m* and signal channel *l*. % % The variable *a* contains the distance in samples between two % consequtive blocks of coefficients. The variable *M* contains the % number of channels for each block of coefficients. Both *a* and *M* are % vectors of integers. % % The variables *g*, *a* and *M* must have the same length, and the result *c* % will also have the same length. % % The time positions of the coefficients blocks can be obtained by the % following code. A value of 0 correspond to the first sample of the % signal:: % % timepos = cumsum(a)-a(1); % % `[c,Ls]=unsdgtreal(f,g,a,M)` additionally returns the length *Ls* of the input % signal *f*. This is handy for reconstruction:: % % [c,Ls]=unsdgtreal(f,g,a,M); % fr=insdgtreal(c,gd,a,Ls); % % will reconstruct the signal *f* no matter what the length of *f* is, % provided that *gd* are dual windows of *g*. % % Notes: % ------ % % `unsdgtreal` uses circular border conditions, that is to say that the signal is % considered as periodic for windows overlapping the beginning or the % end of the signal. % % The phaselocking convention used in `unsdgtreal` is different from the % convention used in the |dgt|_ function. `unsdgtreal` results are phaselocked (a % phase reference moving with the window is used), whereas |dgt|_ results are % not phaselocked (a fixed phase reference corresponding to time 0 of the % signal is used). See the help on |phaselock|_ for more details on % phaselocking conventions. % % See also: nsdgt, insdgtreal, nsgabdual, nsgabtight, phaselock % % Demos: demo_nsdgt % % References: ltfatnote018 % AUTHOR : Florent Jaillet % TESTING: TEST_NSDGTREAL % REFERENCE: if ~isnumeric(a) error('%s: a must be numeric.',upper(callfun)); end; if ~isnumeric(M) error('%s: M must be numeric.',upper(callfun)); end; L=sum(a); [f,Ls,W,wasrow,remembershape]=comp_sigreshape_pre(f,'UNSDGTREAL',0); f=postpad(f,L); [g,info]=nsgabwin(g,a,M); timepos=cumsum(a)-a(1); N=length(a); % Number of time positions M2=floor(M/2)+1; c=zeros(M2,N,W); % Initialisation of the result for ii=1:N shift=floor(length(g{ii})/2); temp=zeros(M,W); % Windowing of the signal. % Possible improvements: The following could be computed faster by % explicitely computing the indexes instead of using modulo and the % repmat is not needed if the number of signal channels W=1 (but the time % difference when removing it whould be really small) temp(1:length(g{ii}))=f(mod((1:length(g{ii}))+timepos(ii)-shift-1,L)+1,:).*... repmat(conj(circshift(g{ii},shift)),1,W); temp=circshift(temp,-shift); if M