Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[4530c5]: blockproc / blocksyn.m Maximize Restore History

Download this file

blocksyn.m    91 lines (83 with data), 2.7 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
function fhat = blocksyn(F, c , Lb)
%BLOCKSYN Blockwise synthesis interface
% Usage: blocksyn(F, c, Lb)
%
% Input parameters:
% Fs : Synthesis frame object.
% c : Coefficients of a block.
% Output parameters:
% fhat : Reconstructed block of signal.
%
% `c=blocksyn(Fs,c,Lb)` reconstructs the signal block *fhat* from the coefficients *c*
% using the frame defined by *Fs*.
%
% *Note:* To get perfect reconstruction, the synthesis frame *Fs* must
% be a dual frame of the analysis frame used in |blockana|.
%
% See also: block, blockana, framedual
if nargin<3
error('%s: Too few input parameters.',upper(mfilename));
end;
if ~isstruct(F)
error('%s: First agument must be a frame definition structure.',upper(mfilename));
end;
% Next block index start (from a global point of view, starting with zero)
nextSb = block_interface('getPos');
% Block index start (from a global point of view, starting with zero)
Sb = nextSb-Lb;
switch(F.type)
case 'fwt'
% The SegDWT algorithm
J = F.J;
w = F.g;
m = numel(w.g{1}.h);
a = w.a(1);
blocksize = a^J;
r = (a^J-1)/(a-1)*(m-1);
Lbrec = (floor(nextSb/blocksize) - floor(Sb/blocksize))*blocksize;
rSb = (a^J-1)/(a-1)*(m-a) + mod(Sb,a^J);
over = r - rSb;
f = block_ifwt(c,w,J,Lbrec);
ol = loadOverlap(r-mod(Sb, a^J),size(c,2));
olLen = size(ol,1);
f(1:olLen-over,:) = f(1:olLen-over,:) + ol(1+over:end,:);
f = [ol(1:over,:);f];
storeOverlap(f,r-mod(nextSb, a^J));
fhat = f(1:Lb,:);
otherwise
% General processing
% Equal block length assumtion
% Reconstruct
f = F.frsyn(c);
% Result should not be longer than 2*Lb
f = f(1:2*Lb,:);
% Load and add overlap (first half)
ol = loadOverlap(Lb,size(c,2));
olLen = size(ol,1);
f(1:olLen,:) = f(1:olLen,:) + ol;
% Store overlap (second half)
storeOverlap(f,Lb);
% Return first half
fhat = f(1:Lb,:);
end
end
function overlap = loadOverlap(L,chan)
overlap = block_interface('getSynOverlap');
if isempty(overlap)
overlap = zeros(L,chan);
end
Lo = size(overlap,1);
if nargin<1
L = Lo;
end
if L>Lo
error('%s: Required more samples than stored.',upper(mfilename));
end
overlap = overlap(end-L+1:end,:);
end
function storeOverlap(fext,L)
if L>size(fext)
error('%s: Required more samples.',upper(mfilename));
end
block_interface('setSynOverlap',fext(end-L+1:end,:));
end