function [X] = dcells2spec(Y,zpf)
% DCELLS2SPEC - Convert dyadic spectral cells Y to spectrum X
%           
% Origin: http://ccrma.stanford.edu/~jos/sasp/dcells2spec.m
%
% Reference:
%   http://ccrma.stanford.edu/~jos/sasp/Audio_Filter_Banks.html
%
% Example Usage:
%   http://ccrma.stanford.edu/~jos/sasp/Spectral_Rotation_Real_Signals.html

if nargin<2, zpf=1; end

NS = length(Y)-1; % Number of dyadic cells (minus one for dc band)

if NS>1 && length(Y{1}) == length(Y{2})
  % No spectral aliasing (no time-domain downsampling) used:
  N0zp = length(Y{1}); % full spectrum already passed 
  X = zeros(NS+1,N0zp);
  for k=1:NS+1
    X(k,:) = Y{k};
  end
else % spectral blocks are critically aliased:
  N0zp = 2*length(Y{1});
  N0 = N0zp/zpf;
  N = N0 * 2 .^ -(1:NS+1); % Spectral widths in bins of dyadic cells
  N(NS+1)=N(NS);
  Nzpf = N*zpf;
  X = zeros(NS+1,N0zp);
  for k=1:NS
    X(k,:) = [zeros(1,Nzpf(k)), Y{k}, zeros(1,N0zp-2*Nzpf(k))];
  end
  X(NS+1,:) = [Y{NS+1}, zeros(1,N0zp-Nzpf(k))];
end
