You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
4.5 KiB
104 lines
4.5 KiB
6 years ago
|
function frameF = filterbank(frameT, frameType, winType)
|
||
|
%Implementation of the Filter Bank step
|
||
|
% Usage frameF = filterbank(frameT, frameType, winType), where:
|
||
|
% Inputs
|
||
|
% - frameT is a frame in the time domain, containing both channels of
|
||
|
% the audio stored in an array of dimensions 2048X2
|
||
|
% - frameType is the type of the current frame in string
|
||
|
% representation, can be one of "OLS" (ONLY_LONG_SEQUENCE), "LSS"
|
||
|
% (LONG_START_SEQUENCE), "ESH" (EIGHT_SHORT_SEQUENCE), "LPS"
|
||
|
% (LONG_STOP_SEQUENCE)
|
||
|
% - winType is the type of the window selected, can be one of "KBD",
|
||
|
% "SIN"
|
||
|
%
|
||
|
% Output
|
||
|
% - frameF is the frame in the frequency domain, in MDCT coefficients
|
||
|
% representation containing both channels of the audio stored in an
|
||
|
% array of dimensions 1024X2
|
||
|
|
||
|
% Declares persistent windows variables and initializes if empty
|
||
|
persistent kaiserWindowLong kaiserWindowShort sinWindowLong sinWindowShort;
|
||
|
if isempty(kaiserWindowLong) || isempty(kaiserWindowShort) || ...
|
||
|
isempty(sinWindowLong) || isempty(sinWindowShort)
|
||
|
kaiserLong = kaiser(1024, 6*pi);
|
||
|
kaiserSumLong = sum(kaiserLong);
|
||
|
kaiserShort = kaiser(128, 4*pi);
|
||
|
kaiserSumShort = sum(kaiserShort);
|
||
|
|
||
|
for n = 1:1024
|
||
|
kaiserWindowLong(n) = sqrt(sum(kaiserLong(1:n))/kaiserSumLong);
|
||
|
kaiserWindowLong(1024 + n) = sqrt(sum(kaiserLong(1:end-n+1))/kaiserSumLong);
|
||
|
|
||
|
sinWindowLong(n) = sin(pi*(n + 0.5)/2048);
|
||
|
sinWindowLong(1024 + n) = sin(pi*(1024 + n + 0.5)/2048);
|
||
|
|
||
|
end
|
||
|
|
||
|
for n = 1:128
|
||
|
kaiserWindowShort(n) = sqrt(sum(kaiserShort(1:n))/kaiserSumShort);
|
||
|
kaiserWindowShort(128 + n) = sqrt(sum(kaiserShort(1:end-n+1))/kaiserSumShort);
|
||
|
|
||
|
sinWindowShort(n) = sin(pi*(n + 0.5)/256);
|
||
|
sinWindowShort(128 + n) = sin(pi*(128 + n + 0.5)/256);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
frameF(1024, 2) = 0;
|
||
|
|
||
|
% Applies appropriate window to the frame
|
||
|
for channel=1:2
|
||
|
if strcmp(frameType, 'OLS')
|
||
|
if strcmp(winType, 'KBD')
|
||
|
frameT(:, channel) = frameT(:, channel) .* kaiserWindowLong(:);
|
||
|
elseif strcmp(winType, 'SIN')
|
||
|
frameT(:, channel) = frameT(:, channel) .* sinWindowLong(:);
|
||
|
else
|
||
|
error('filterbank, l[20]: Unsupported window type input!')
|
||
|
end
|
||
|
|
||
|
frameF(:, channel) = mdct4(frameT(:, channel));
|
||
|
elseif strcmp(frameType, 'LSS')
|
||
|
if strcmp(winType, 'KBD')
|
||
|
frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)';
|
||
|
frameT(1473:1600, channel) = frameT(1473:1600, channel) .* kaiserWindowShort(129:end)';
|
||
|
frameT(1601:end, channel) = 0;
|
||
|
elseif strcmp(winType, 'SIN')
|
||
|
frameT(1:1024, channel) = frameT(1:1024, channel) .* sinWindowLong(1:1024)';
|
||
|
frameT(1473:1600, channel) = frameT(1473:1600, channel) .* sinWindowShort(129:end)';
|
||
|
frameT(1601:end, channel) = 0;
|
||
|
else
|
||
|
error('filterbank, l[20]: Unsupported window type input!')
|
||
|
end
|
||
|
|
||
|
frameF(:, channel) = mdct4(frameT(:, channel));
|
||
|
elseif strcmp(frameType, 'LPS')
|
||
|
if strcmp(winType, 'KBD')
|
||
|
frameT(1:448, channel) = 0;
|
||
|
frameT(449:576, channel) = frameT(449:576, channel) .* kaiserWindowShort(1:128)';
|
||
|
frameT(1025:end, channel) = frameT(1025:end, channel) .* kaiserWindowLong(1025:end)';
|
||
|
elseif strcmp(winType, 'SIN')
|
||
|
frameT(1:448, channel) = 0;
|
||
|
frameT(449:576, channel) = frameT(449:576, channel) .* sinWindowShort(1:128)';
|
||
|
frameT(1025:end, channel) = frameT(1025:end, channel) .* sinWindowLong(1025:end)';
|
||
|
else
|
||
|
error('filterbank, l[20]: Unsupported window type input!')
|
||
|
end
|
||
|
|
||
|
frameF(:, channel) = mdct4(frameT(:, channel));
|
||
|
elseif strcmp(frameType, 'ESH')
|
||
|
% Splits the frame into sub-frames
|
||
|
[subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay');
|
||
|
|
||
|
if strcmp(winType, 'KBD')
|
||
|
subFrames = subFrames .* repmat(kaiserWindowShort', [1 8]);
|
||
|
elseif strcmp(winType, 'SIN')
|
||
|
subFrames = subFrames .* repmat(sinWindowShort', [1 8]);
|
||
|
end
|
||
|
|
||
|
for subFrameIndex = 1:8
|
||
|
frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel) = mdct4(subFrames(:, subFrameIndex));
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|