function output = dft_block(input,blocksize);

% function output = dft_block3(input,blocksize);
%
% Applies the DFT to 1 by blocksize blocks of input.
% Extracts the real part of coefficients 2 through 1+blocksize/2.
% and the imaginary parts of coefficients 2 through blocksize/2.
% Multiplies all coefficients except real parts of coefficients 1
% and blocksize/2 by sqrt(2) and by 1/blocksize.  This causes the DC value
% to be the average of the elements of one block, and it causes the
% the sum of the squares of the blocks to equal 1/blocksize times the
% the sum of the squares of the coefficients.
%
% blocksize is an optional argument with default size 8.
%
% inverse_dft_block.m  does the inverse of  dft_block
%
% MB, DN 10/4/01

if ~exist('blocksize','var') | isempty(blocksize)
    blocksize = 8;
end

sz = size(input);

% Reshape the input into a three dimensional matrix
output = input;
output = reshape(output,[sz(1),blocksize,sz(2)/blocksize]);
output = permute(output,[1 3 2]);

% Compute the fft along the 3rd dimension
output = fft(output,[],3)/blocksize;

% Extract and collect the desired components 
output(:,:,(blocksize/2+2:blocksize)) = sqrt(2) * imag(output(:,:,2:(blocksize/2)));
output(:,:,2:blocksize/2) = sqrt(2) * real(output(:,:,2:blocksize/2));



