diff --git a/Level_1/AACoder1.m b/Level_1/AACoder1.m index 6422fb6..665c745 100644 --- a/Level_1/AACoder1.m +++ b/Level_1/AACoder1.m @@ -18,7 +18,7 @@ function AACSeq1 = AACoder1(fNameIn) [originalAudioData, ~] = audioread(fNameIn); % Splits the audio in frames and determines the type of each frame - frameTypes{fix((length(originalAudioData) - 1025) / 1024)} = 'OLS'; + frameTypes{fix((length(originalAudioData) - 1025) / 1024), 1} = 'OLS'; frameTypes{1} = 'OLS'; for i = 1:length(frameTypes) - 2 nextFrameStart = (i + 1) * 1024 + 1; @@ -36,7 +36,7 @@ function AACSeq1 = AACoder1(fNameIn) end % Encodes audio file - AACSeq1(length(frameTypes)) = struct; + AACSeq1(length(frameTypes), 1) = struct; for i = 0:length(frameTypes) - 1 currFrameStart = i * 1024 + 1; currFrameStop = currFrameStart + 2047; diff --git a/Level_1/SSC.m b/Level_1/SSC.m index e0f4502..3f59ed8 100644 --- a/Level_1/SSC.m +++ b/Level_1/SSC.m @@ -34,12 +34,12 @@ function frameType = SSC(~, nextFrameT, prevFrameType) for channel = 1:2 % Calculates sub-frame energy estimation [subFrames, ~] = buffer(nextFrameT(577:end - 448, channel), 128, 0, 'nodelay'); - energyEstimations = sum(subFrames .^ 2, 1); + energyEstimations = sum(subFrames .^ 2, 1)'; % Calculates the ratio of the sub-frame energy to the average energy of % the previous sub-frames energyRatios = movmean(energyEstimations, [8 0]); - energyRatios = energyEstimations ./ [energyEstimations(1) energyRatios(1:end-1)]; + energyRatios = energyEstimations ./ [energyEstimations(1); energyRatios(1:end-1)]; if ~isempty(find(energyEstimations > 10^(-3), 1)) && ... ~isempty(find(energyRatios(energyEstimations > 10^(-3)) > 10, 1)) diff --git a/Level_1/filterbank.m b/Level_1/filterbank.m index 56ab914..f1ebdfd 100644 --- a/Level_1/filterbank.m +++ b/Level_1/filterbank.m @@ -25,17 +25,17 @@ function frameF = filterbank(frameT, frameType, winType) kaiserShort = kaiser(129, 4*pi); kaiserSumShort = sum(kaiserShort); - kaiserWindowLong(1:1024) = movsum(kaiserLong(1:1024), [1024 0]); - kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); + kaiserWindowLong(1:1024, 1) = movsum(kaiserLong(1:1024), [1024 0]); + kaiserWindowLong(1025:2048, 1) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong); - sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048); + sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048)'; - kaiserWindowShort(1:128) = movsum(kaiserShort(1:128), [128 0]); - kaiserWindowShort(129:256) = movsum(flipud(kaiserShort(1:128)), [0 128]); + kaiserWindowShort(1:128, 1) = movsum(kaiserShort(1:128), [128 0]); + kaiserWindowShort(129:256, 1) = movsum(flipud(kaiserShort(1:128)), [0 128]); kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort); - sinWindowShort = sin(pi * ((0:255) + 0.5) / 256); + sinWindowShort = sin(pi * ((0:255) + 0.5) / 256)'; end % Initializes output array @@ -44,9 +44,9 @@ function frameF = filterbank(frameT, frameType, winType) % Applies appropriate window to the frame if strcmp(frameType, 'OLS') if strcmp(winType, 'KBD') - frameT = bsxfun(@times, frameT, kaiserWindowLong'); + frameT = bsxfun(@times, frameT, kaiserWindowLong); elseif strcmp(winType, 'SIN') - frameT = bsxfun(@times, frameT, sinWindowLong'); + frameT = bsxfun(@times, frameT, sinWindowLong); else error('filterbank, l[20]: Unsupported window type input!') end @@ -54,12 +54,12 @@ function frameF = filterbank(frameT, frameType, winType) frameF = mdct4(frameT); elseif strcmp(frameType, 'LSS') if strcmp(winType, 'KBD') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)); frameT(1601:end, :) = 0; elseif strcmp(winType, 'SIN') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else error('filterbank, l[20]: Unsupported window type input!') @@ -69,12 +69,12 @@ function frameF = filterbank(frameT, frameType, winType) elseif strcmp(frameType, 'LPS') if strcmp(winType, 'KBD') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)); elseif strcmp(winType, 'SIN') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)); else error('filterbank, l[20]: Unsupported window type input!') end @@ -86,9 +86,9 @@ function frameF = filterbank(frameT, frameType, winType) [subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay'); if strcmp(winType, 'KBD') - subFrames = subFrames .* repmat(kaiserWindowShort', [1 8]); + subFrames = subFrames .* repmat(kaiserWindowShort, [1 8]); elseif strcmp(winType, 'SIN') - subFrames = subFrames .* repmat(sinWindowShort', [1 8]); + subFrames = subFrames .* repmat(sinWindowShort, [1 8]); end for subFrameIndex = 1:8 diff --git a/Level_1/iFilterbank.m b/Level_1/iFilterbank.m index 683be02..57f9456 100644 --- a/Level_1/iFilterbank.m +++ b/Level_1/iFilterbank.m @@ -25,17 +25,17 @@ function frameT = iFilterbank(frameF, frameType, winType) kaiserShort = kaiser(129, 4*pi); kaiserSumShort = sum(kaiserShort); - kaiserWindowLong(1:1024) = movsum(kaiserLong(1:1024), [1024 0]); - kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); + kaiserWindowLong(1:1024, 1) = movsum(kaiserLong(1:1024), [1024 0]); + kaiserWindowLong(1025:2048, 1) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong); - sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048); + sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048)'; - kaiserWindowShort(1:128) = movsum(kaiserShort(1:128), [128 0]); - kaiserWindowShort(129:256) = movsum(flipud(kaiserShort(1:128)), [0 128]); + kaiserWindowShort(1:128, 1) = movsum(kaiserShort(1:128), [128 0]); + kaiserWindowShort(129:256, 1) = movsum(flipud(kaiserShort(1:128)), [0 128]); kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort); - sinWindowShort = sin(pi * ((0:255) + 0.5) / 256); + sinWindowShort = sin(pi * ((0:255) + 0.5) / 256)'; end % Initializes output array @@ -46,9 +46,9 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT = imdct4(frameF); if strcmp(winType, 'KBD') - frameT = bsxfun(@times, frameT, kaiserWindowLong'); + frameT = bsxfun(@times, frameT, kaiserWindowLong); elseif strcmp(winType, 'SIN') - frameT = bsxfun(@times, frameT, sinWindowLong'); + frameT = bsxfun(@times, frameT, sinWindowLong); else error('filterbank, l[20]: Unsupported window type input!') end @@ -56,12 +56,12 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT = imdct4(frameF); if strcmp(winType, 'KBD') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)); frameT(1601:end, :) = 0; elseif strcmp(winType, 'SIN') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else error('filterbank, l[20]: Unsupported window type input!') @@ -71,12 +71,12 @@ function frameT = iFilterbank(frameF, frameType, winType) if strcmp(winType, 'KBD') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)); elseif strcmp(winType, 'SIN') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)); else error('filterbank, l[20]: Unsupported window type input!') end @@ -86,9 +86,9 @@ function frameT = iFilterbank(frameF, frameType, winType) subFrame = imdct4(frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel)); if strcmp(winType, 'KBD') - subFrame = subFrame .* kaiserWindowShort'; + subFrame = subFrame .* kaiserWindowShort; elseif strcmp(winType, 'SIN') - subFrame = subFrame .* sinWindowShort'; + subFrame = subFrame .* sinWindowShort; end frameT(448 + (subFrameIndex - 1) * 128 + 1:448 + (subFrameIndex + 1) * 128, channel) = ... diff --git a/Level_2/AACoder2.m b/Level_2/AACoder2.m index 4e7864f..21dc7c4 100644 --- a/Level_2/AACoder2.m +++ b/Level_2/AACoder2.m @@ -21,7 +21,7 @@ function AACSeq2 = AACoder2(fNameIn) [originalAudioData, ~] = audioread(fNameIn); % Splits the audio in frames and determines the type of each frame - frameTypes{fix((length(originalAudioData) - 1025) / 1024)} = 'OLS'; + frameTypes{fix((length(originalAudioData) - 1025) / 1024), 1} = 'OLS'; frameTypes{1} = 'OLS'; for i = 1:length(frameTypes) - 2 nextFrameStart = (i + 1) * 1024 + 1; @@ -39,7 +39,7 @@ function AACSeq2 = AACoder2(fNameIn) end % Encodes audio file - AACSeq2(length(frameTypes)) = struct; + AACSeq2(length(frameTypes), 1) = struct; for i = 0:length(frameTypes) - 1 currFrameStart = i * 1024 + 1; currFrameStop = currFrameStart + 2047; diff --git a/Level_2/SSC.m b/Level_2/SSC.m index e0f4502..3f59ed8 100644 --- a/Level_2/SSC.m +++ b/Level_2/SSC.m @@ -34,12 +34,12 @@ function frameType = SSC(~, nextFrameT, prevFrameType) for channel = 1:2 % Calculates sub-frame energy estimation [subFrames, ~] = buffer(nextFrameT(577:end - 448, channel), 128, 0, 'nodelay'); - energyEstimations = sum(subFrames .^ 2, 1); + energyEstimations = sum(subFrames .^ 2, 1)'; % Calculates the ratio of the sub-frame energy to the average energy of % the previous sub-frames energyRatios = movmean(energyEstimations, [8 0]); - energyRatios = energyEstimations ./ [energyEstimations(1) energyRatios(1:end-1)]; + energyRatios = energyEstimations ./ [energyEstimations(1); energyRatios(1:end-1)]; if ~isempty(find(energyEstimations > 10^(-3), 1)) && ... ~isempty(find(energyRatios(energyEstimations > 10^(-3)) > 10, 1)) diff --git a/Level_2/TNS.m b/Level_2/TNS.m index 672c621..866417e 100644 --- a/Level_2/TNS.m +++ b/Level_2/TNS.m @@ -34,7 +34,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) if ~strcmp(frameType, 'ESH') % Calculates the energy per band - bandEnergy(LONG_WINDOW_NUMBER_OF_BANDS) = 0; + bandEnergy(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; for band = 1:LONG_WINDOW_NUMBER_OF_BANDS - 1 bandEnergy(band) = sumsqr(frameFin(TNSTables.B219a(band, 2) + 1:TNSTables.B219a(band + 1, 2))); end @@ -42,7 +42,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) TNSTables.B219a(LONG_WINDOW_NUMBER_OF_BANDS, 2) + 1:end)); % Calculates the normalization factors - bandIndices = quantiz(0:1023, TNSTables.B219a(:, 2) - 1); + bandIndices = quantiz(0:1023, TNSTables.B219a(:, 2) - 1)'; normalizationFactor = sqrt(bandEnergy(bandIndices)); % Smooths normalization factors @@ -54,7 +54,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) end % Normalizes MDCT coefficients according to each band energy - normalizedFrameFin = frameFin ./ normalizationFactor'; + normalizedFrameFin = frameFin ./ normalizationFactor; % Calculates the linear prediction coefficients [linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER); @@ -66,15 +66,15 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) if ~isstable(1, quantizedLinPredCoeff) error('TNS, l[79]: Inverse filter not stable!'); else - TNScoeffs = quantizedLinPredCoeff(2:end); + TNScoeffs = quantizedLinPredCoeff(2:end)'; frameFout = filter(quantizedLinPredCoeff, 1, frameFin); end else % Initializes output vectors - TNScoeffs(LPF_ORDER * 8) = 0; + TNScoeffs(LPF_ORDER * 8, 1) = 0; frameFout(1024) = 0; - bandEnergy(SHORT_WINDOW_NUMBER_OF_BANDS) = 0; + bandEnergy(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; for subFrameIndex = 1:8 subFrame = frameFin((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128); @@ -86,7 +86,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) TNSTables.B219b(SHORT_WINDOW_NUMBER_OF_BANDS, 2) + 1:end)); % Calculates the normalization factors - bandIndices = quantiz(0:127, TNSTables.B219b(:, 2) - 1); + bandIndices = quantiz(0:127, TNSTables.B219b(:, 2) - 1)'; normalizationFactor = sqrt(bandEnergy(bandIndices)); % Smooths normalization factors @@ -98,7 +98,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) end % Normalizes MDCT coefficients according to each band energy - normalizedFrameFin = subFrame ./ normalizationFactor'; + normalizedFrameFin = subFrame ./ normalizationFactor; % Calculates the linear prediction coefficients [linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER); diff --git a/Level_2/filterbank.m b/Level_2/filterbank.m index 56ab914..f1ebdfd 100644 --- a/Level_2/filterbank.m +++ b/Level_2/filterbank.m @@ -25,17 +25,17 @@ function frameF = filterbank(frameT, frameType, winType) kaiserShort = kaiser(129, 4*pi); kaiserSumShort = sum(kaiserShort); - kaiserWindowLong(1:1024) = movsum(kaiserLong(1:1024), [1024 0]); - kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); + kaiserWindowLong(1:1024, 1) = movsum(kaiserLong(1:1024), [1024 0]); + kaiserWindowLong(1025:2048, 1) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong); - sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048); + sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048)'; - kaiserWindowShort(1:128) = movsum(kaiserShort(1:128), [128 0]); - kaiserWindowShort(129:256) = movsum(flipud(kaiserShort(1:128)), [0 128]); + kaiserWindowShort(1:128, 1) = movsum(kaiserShort(1:128), [128 0]); + kaiserWindowShort(129:256, 1) = movsum(flipud(kaiserShort(1:128)), [0 128]); kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort); - sinWindowShort = sin(pi * ((0:255) + 0.5) / 256); + sinWindowShort = sin(pi * ((0:255) + 0.5) / 256)'; end % Initializes output array @@ -44,9 +44,9 @@ function frameF = filterbank(frameT, frameType, winType) % Applies appropriate window to the frame if strcmp(frameType, 'OLS') if strcmp(winType, 'KBD') - frameT = bsxfun(@times, frameT, kaiserWindowLong'); + frameT = bsxfun(@times, frameT, kaiserWindowLong); elseif strcmp(winType, 'SIN') - frameT = bsxfun(@times, frameT, sinWindowLong'); + frameT = bsxfun(@times, frameT, sinWindowLong); else error('filterbank, l[20]: Unsupported window type input!') end @@ -54,12 +54,12 @@ function frameF = filterbank(frameT, frameType, winType) frameF = mdct4(frameT); elseif strcmp(frameType, 'LSS') if strcmp(winType, 'KBD') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)); frameT(1601:end, :) = 0; elseif strcmp(winType, 'SIN') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else error('filterbank, l[20]: Unsupported window type input!') @@ -69,12 +69,12 @@ function frameF = filterbank(frameT, frameType, winType) elseif strcmp(frameType, 'LPS') if strcmp(winType, 'KBD') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)); elseif strcmp(winType, 'SIN') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)); else error('filterbank, l[20]: Unsupported window type input!') end @@ -86,9 +86,9 @@ function frameF = filterbank(frameT, frameType, winType) [subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay'); if strcmp(winType, 'KBD') - subFrames = subFrames .* repmat(kaiserWindowShort', [1 8]); + subFrames = subFrames .* repmat(kaiserWindowShort, [1 8]); elseif strcmp(winType, 'SIN') - subFrames = subFrames .* repmat(sinWindowShort', [1 8]); + subFrames = subFrames .* repmat(sinWindowShort, [1 8]); end for subFrameIndex = 1:8 diff --git a/Level_2/iFilterbank.m b/Level_2/iFilterbank.m index 683be02..57f9456 100644 --- a/Level_2/iFilterbank.m +++ b/Level_2/iFilterbank.m @@ -25,17 +25,17 @@ function frameT = iFilterbank(frameF, frameType, winType) kaiserShort = kaiser(129, 4*pi); kaiserSumShort = sum(kaiserShort); - kaiserWindowLong(1:1024) = movsum(kaiserLong(1:1024), [1024 0]); - kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); + kaiserWindowLong(1:1024, 1) = movsum(kaiserLong(1:1024), [1024 0]); + kaiserWindowLong(1025:2048, 1) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong); - sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048); + sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048)'; - kaiserWindowShort(1:128) = movsum(kaiserShort(1:128), [128 0]); - kaiserWindowShort(129:256) = movsum(flipud(kaiserShort(1:128)), [0 128]); + kaiserWindowShort(1:128, 1) = movsum(kaiserShort(1:128), [128 0]); + kaiserWindowShort(129:256, 1) = movsum(flipud(kaiserShort(1:128)), [0 128]); kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort); - sinWindowShort = sin(pi * ((0:255) + 0.5) / 256); + sinWindowShort = sin(pi * ((0:255) + 0.5) / 256)'; end % Initializes output array @@ -46,9 +46,9 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT = imdct4(frameF); if strcmp(winType, 'KBD') - frameT = bsxfun(@times, frameT, kaiserWindowLong'); + frameT = bsxfun(@times, frameT, kaiserWindowLong); elseif strcmp(winType, 'SIN') - frameT = bsxfun(@times, frameT, sinWindowLong'); + frameT = bsxfun(@times, frameT, sinWindowLong); else error('filterbank, l[20]: Unsupported window type input!') end @@ -56,12 +56,12 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT = imdct4(frameF); if strcmp(winType, 'KBD') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)); frameT(1601:end, :) = 0; elseif strcmp(winType, 'SIN') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else error('filterbank, l[20]: Unsupported window type input!') @@ -71,12 +71,12 @@ function frameT = iFilterbank(frameF, frameType, winType) if strcmp(winType, 'KBD') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)); elseif strcmp(winType, 'SIN') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)); else error('filterbank, l[20]: Unsupported window type input!') end @@ -86,9 +86,9 @@ function frameT = iFilterbank(frameF, frameType, winType) subFrame = imdct4(frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel)); if strcmp(winType, 'KBD') - subFrame = subFrame .* kaiserWindowShort'; + subFrame = subFrame .* kaiserWindowShort; elseif strcmp(winType, 'SIN') - subFrame = subFrame .* sinWindowShort'; + subFrame = subFrame .* sinWindowShort; end frameT(448 + (subFrameIndex - 1) * 128 + 1:448 + (subFrameIndex + 1) * 128, channel) = ... diff --git a/Level_2/iTNS.m b/Level_2/iTNS.m index d14426c..4c1e8b0 100644 --- a/Level_2/iTNS.m +++ b/Level_2/iTNS.m @@ -25,14 +25,14 @@ function frameFout = iTNS(frameFin, frameType, TNScoeffs) if ~strcmp(frameType, 'ESH') % Inverses MDCT coefficients filtering - frameFout = filter(1, [1 TNScoeffs], frameFin); + frameFout = filter(1, [1; TNScoeffs], frameFin); else for subFrameIndex = 1:8 subFrame = frameFin((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128); % Inverses MDCT coefficients filtering frameFout((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128) = ... - filter(1, [1 TNScoeffs((subFrameIndex - 1) * 4 + 1:subFrameIndex * 4)], subFrame); + filter(1, [1; TNScoeffs((subFrameIndex - 1) * 4 + 1:subFrameIndex * 4)], subFrame); end end end diff --git a/Level_3/AACoder3.m b/Level_3/AACoder3.m index 98ec16b..d322cb2 100644 --- a/Level_3/AACoder3.m +++ b/Level_3/AACoder3.m @@ -44,7 +44,7 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) [originalAudioData, ~] = audioread(fNameIn); % Splits the audio in frames and determines the type of each frame - frameTypes{fix((length(originalAudioData) - 1025) / 1024)} = 'OLS'; + frameTypes{fix((length(originalAudioData) - 1025) / 1024), 1} = 'OLS'; frameTypes{1} = 'OLS'; for i = 1:length(frameTypes) - 2 nextFrameStart = (i + 1) * 1024 + 1; @@ -63,7 +63,7 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) % Encodes audio file huffLUT = loadLUT(); - AACSeq3(length(frameTypes)) = struct; + AACSeq3(length(frameTypes), 1) = struct; for i = 0:length(frameTypes) - 1 currFrameStart = i * 1024 + 1; currFrameStop = currFrameStart + 2047; diff --git a/Level_3/SSC.m b/Level_3/SSC.m index e0f4502..3f59ed8 100644 --- a/Level_3/SSC.m +++ b/Level_3/SSC.m @@ -34,12 +34,12 @@ function frameType = SSC(~, nextFrameT, prevFrameType) for channel = 1:2 % Calculates sub-frame energy estimation [subFrames, ~] = buffer(nextFrameT(577:end - 448, channel), 128, 0, 'nodelay'); - energyEstimations = sum(subFrames .^ 2, 1); + energyEstimations = sum(subFrames .^ 2, 1)'; % Calculates the ratio of the sub-frame energy to the average energy of % the previous sub-frames energyRatios = movmean(energyEstimations, [8 0]); - energyRatios = energyEstimations ./ [energyEstimations(1) energyRatios(1:end-1)]; + energyRatios = energyEstimations ./ [energyEstimations(1); energyRatios(1:end-1)]; if ~isempty(find(energyEstimations > 10^(-3), 1)) && ... ~isempty(find(energyRatios(energyEstimations > 10^(-3)) > 10, 1)) diff --git a/Level_3/TNS.m b/Level_3/TNS.m index 672c621..866417e 100644 --- a/Level_3/TNS.m +++ b/Level_3/TNS.m @@ -34,7 +34,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) if ~strcmp(frameType, 'ESH') % Calculates the energy per band - bandEnergy(LONG_WINDOW_NUMBER_OF_BANDS) = 0; + bandEnergy(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; for band = 1:LONG_WINDOW_NUMBER_OF_BANDS - 1 bandEnergy(band) = sumsqr(frameFin(TNSTables.B219a(band, 2) + 1:TNSTables.B219a(band + 1, 2))); end @@ -42,7 +42,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) TNSTables.B219a(LONG_WINDOW_NUMBER_OF_BANDS, 2) + 1:end)); % Calculates the normalization factors - bandIndices = quantiz(0:1023, TNSTables.B219a(:, 2) - 1); + bandIndices = quantiz(0:1023, TNSTables.B219a(:, 2) - 1)'; normalizationFactor = sqrt(bandEnergy(bandIndices)); % Smooths normalization factors @@ -54,7 +54,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) end % Normalizes MDCT coefficients according to each band energy - normalizedFrameFin = frameFin ./ normalizationFactor'; + normalizedFrameFin = frameFin ./ normalizationFactor; % Calculates the linear prediction coefficients [linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER); @@ -66,15 +66,15 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) if ~isstable(1, quantizedLinPredCoeff) error('TNS, l[79]: Inverse filter not stable!'); else - TNScoeffs = quantizedLinPredCoeff(2:end); + TNScoeffs = quantizedLinPredCoeff(2:end)'; frameFout = filter(quantizedLinPredCoeff, 1, frameFin); end else % Initializes output vectors - TNScoeffs(LPF_ORDER * 8) = 0; + TNScoeffs(LPF_ORDER * 8, 1) = 0; frameFout(1024) = 0; - bandEnergy(SHORT_WINDOW_NUMBER_OF_BANDS) = 0; + bandEnergy(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; for subFrameIndex = 1:8 subFrame = frameFin((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128); @@ -86,7 +86,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) TNSTables.B219b(SHORT_WINDOW_NUMBER_OF_BANDS, 2) + 1:end)); % Calculates the normalization factors - bandIndices = quantiz(0:127, TNSTables.B219b(:, 2) - 1); + bandIndices = quantiz(0:127, TNSTables.B219b(:, 2) - 1)'; normalizationFactor = sqrt(bandEnergy(bandIndices)); % Smooths normalization factors @@ -98,7 +98,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) end % Normalizes MDCT coefficients according to each band energy - normalizedFrameFin = subFrame ./ normalizationFactor'; + normalizedFrameFin = subFrame ./ normalizationFactor; % Calculates the linear prediction coefficients [linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER); diff --git a/Level_3/filterbank.m b/Level_3/filterbank.m index 56ab914..f1ebdfd 100644 --- a/Level_3/filterbank.m +++ b/Level_3/filterbank.m @@ -25,17 +25,17 @@ function frameF = filterbank(frameT, frameType, winType) kaiserShort = kaiser(129, 4*pi); kaiserSumShort = sum(kaiserShort); - kaiserWindowLong(1:1024) = movsum(kaiserLong(1:1024), [1024 0]); - kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); + kaiserWindowLong(1:1024, 1) = movsum(kaiserLong(1:1024), [1024 0]); + kaiserWindowLong(1025:2048, 1) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong); - sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048); + sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048)'; - kaiserWindowShort(1:128) = movsum(kaiserShort(1:128), [128 0]); - kaiserWindowShort(129:256) = movsum(flipud(kaiserShort(1:128)), [0 128]); + kaiserWindowShort(1:128, 1) = movsum(kaiserShort(1:128), [128 0]); + kaiserWindowShort(129:256, 1) = movsum(flipud(kaiserShort(1:128)), [0 128]); kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort); - sinWindowShort = sin(pi * ((0:255) + 0.5) / 256); + sinWindowShort = sin(pi * ((0:255) + 0.5) / 256)'; end % Initializes output array @@ -44,9 +44,9 @@ function frameF = filterbank(frameT, frameType, winType) % Applies appropriate window to the frame if strcmp(frameType, 'OLS') if strcmp(winType, 'KBD') - frameT = bsxfun(@times, frameT, kaiserWindowLong'); + frameT = bsxfun(@times, frameT, kaiserWindowLong); elseif strcmp(winType, 'SIN') - frameT = bsxfun(@times, frameT, sinWindowLong'); + frameT = bsxfun(@times, frameT, sinWindowLong); else error('filterbank, l[20]: Unsupported window type input!') end @@ -54,12 +54,12 @@ function frameF = filterbank(frameT, frameType, winType) frameF = mdct4(frameT); elseif strcmp(frameType, 'LSS') if strcmp(winType, 'KBD') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)); frameT(1601:end, :) = 0; elseif strcmp(winType, 'SIN') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else error('filterbank, l[20]: Unsupported window type input!') @@ -69,12 +69,12 @@ function frameF = filterbank(frameT, frameType, winType) elseif strcmp(frameType, 'LPS') if strcmp(winType, 'KBD') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)); elseif strcmp(winType, 'SIN') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)); else error('filterbank, l[20]: Unsupported window type input!') end @@ -86,9 +86,9 @@ function frameF = filterbank(frameT, frameType, winType) [subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay'); if strcmp(winType, 'KBD') - subFrames = subFrames .* repmat(kaiserWindowShort', [1 8]); + subFrames = subFrames .* repmat(kaiserWindowShort, [1 8]); elseif strcmp(winType, 'SIN') - subFrames = subFrames .* repmat(sinWindowShort', [1 8]); + subFrames = subFrames .* repmat(sinWindowShort, [1 8]); end for subFrameIndex = 1:8 diff --git a/Level_3/iFilterbank.m b/Level_3/iFilterbank.m index 683be02..57f9456 100644 --- a/Level_3/iFilterbank.m +++ b/Level_3/iFilterbank.m @@ -25,17 +25,17 @@ function frameT = iFilterbank(frameF, frameType, winType) kaiserShort = kaiser(129, 4*pi); kaiserSumShort = sum(kaiserShort); - kaiserWindowLong(1:1024) = movsum(kaiserLong(1:1024), [1024 0]); - kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); + kaiserWindowLong(1:1024, 1) = movsum(kaiserLong(1:1024), [1024 0]); + kaiserWindowLong(1025:2048, 1) = movsum(flipud(kaiserLong(1:1024)), [0 1024]); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong); - sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048); + sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048)'; - kaiserWindowShort(1:128) = movsum(kaiserShort(1:128), [128 0]); - kaiserWindowShort(129:256) = movsum(flipud(kaiserShort(1:128)), [0 128]); + kaiserWindowShort(1:128, 1) = movsum(kaiserShort(1:128), [128 0]); + kaiserWindowShort(129:256, 1) = movsum(flipud(kaiserShort(1:128)), [0 128]); kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort); - sinWindowShort = sin(pi * ((0:255) + 0.5) / 256); + sinWindowShort = sin(pi * ((0:255) + 0.5) / 256)'; end % Initializes output array @@ -46,9 +46,9 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT = imdct4(frameF); if strcmp(winType, 'KBD') - frameT = bsxfun(@times, frameT, kaiserWindowLong'); + frameT = bsxfun(@times, frameT, kaiserWindowLong); elseif strcmp(winType, 'SIN') - frameT = bsxfun(@times, frameT, sinWindowLong'); + frameT = bsxfun(@times, frameT, sinWindowLong); else error('filterbank, l[20]: Unsupported window type input!') end @@ -56,12 +56,12 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT = imdct4(frameF); if strcmp(winType, 'KBD') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)); frameT(1601:end, :) = 0; elseif strcmp(winType, 'SIN') - frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)'); - frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)'); + frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)); + frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else error('filterbank, l[20]: Unsupported window type input!') @@ -71,12 +71,12 @@ function frameT = iFilterbank(frameF, frameType, winType) if strcmp(winType, 'KBD') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)); elseif strcmp(winType, 'SIN') frameT(1:448, :) = 0; - frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)'); - frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)'); + frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)); + frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)); else error('filterbank, l[20]: Unsupported window type input!') end @@ -86,9 +86,9 @@ function frameT = iFilterbank(frameF, frameType, winType) subFrame = imdct4(frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel)); if strcmp(winType, 'KBD') - subFrame = subFrame .* kaiserWindowShort'; + subFrame = subFrame .* kaiserWindowShort; elseif strcmp(winType, 'SIN') - subFrame = subFrame .* sinWindowShort'; + subFrame = subFrame .* sinWindowShort; end frameT(448 + (subFrameIndex - 1) * 128 + 1:448 + (subFrameIndex + 1) * 128, channel) = ... diff --git a/Level_3/iTNS.m b/Level_3/iTNS.m index d14426c..4c1e8b0 100644 --- a/Level_3/iTNS.m +++ b/Level_3/iTNS.m @@ -25,14 +25,14 @@ function frameFout = iTNS(frameFin, frameType, TNScoeffs) if ~strcmp(frameType, 'ESH') % Inverses MDCT coefficients filtering - frameFout = filter(1, [1 TNScoeffs], frameFin); + frameFout = filter(1, [1; TNScoeffs], frameFin); else for subFrameIndex = 1:8 subFrame = frameFin((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128); % Inverses MDCT coefficients filtering frameFout((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128) = ... - filter(1, [1 TNScoeffs((subFrameIndex - 1) * 4 + 1:subFrameIndex * 4)], subFrame); + filter(1, [1; TNScoeffs((subFrameIndex - 1) * 4 + 1:subFrameIndex * 4)], subFrame); end end end diff --git a/Level_3/psycho.m b/Level_3/psycho.m index 93b7fd8..4ccbf7f 100644 --- a/Level_3/psycho.m +++ b/Level_3/psycho.m @@ -64,17 +64,17 @@ function SMR = psycho(frameT, frameType, frameTprev1, frameTprev2) tmpSum = tmpz + tmpy; spreadingShort(tmpy >= -100) = 10 .^ (tmpSum(tmpy >= -100) ./ 10); - hannLong = 0.5 - 0.5 * cos(pi * ((0:2047) + 0.5) / 1024); - hannShort = 0.5 - 0.5 * cos(pi * ((0:255) + 0.5) / 128); + hannLong = 0.5 - 0.5 * cos(pi * ((0:2047) + 0.5) / 1024)'; + hannShort = 0.5 - 0.5 * cos(pi * ((0:255) + 0.5) / 128)'; clearvars tmpx tmpz tmpy end if ~strcmp(frameType, 'ESH') % Applies window to the frames - windowedFrameT = frameT .* hannLong'; - windowedFrameTprev1 = frameTprev1 .* hannLong'; - windowedFrameTprev2 = frameTprev2 .* hannLong'; + windowedFrameT = frameT .* hannLong; + windowedFrameTprev1 = frameTprev1 .* hannLong; + windowedFrameTprev2 = frameTprev2 .* hannLong; % Calculates the FFT of each frame frameF = fft(windowedFrameT); @@ -103,8 +103,8 @@ function SMR = psycho(frameT, frameType, frameTprev1, frameTprev2) % Calculates the energy and weighted predictability in the % threshold calculation partitions - bandEnergy(LONG_WINDOW_NUMBER_OF_BANDS) = 0; - bandPredictability(LONG_WINDOW_NUMBER_OF_BANDS) = 0; + bandEnergy(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; + bandPredictability(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; for band = 1:LONG_WINDOW_NUMBER_OF_BANDS bandEnergy(band) = sumsqr(frameFMag(TNSTables.B219a(band, 2) + 1: ... TNSTables.B219a(band, 3) + 1)); @@ -116,8 +116,8 @@ function SMR = psycho(frameT, frameType, frameTprev1, frameTprev2) % Convolves the partitioned energy and predictability with the % spreading function - bandEnergyConv = sum(bandEnergy .* spreadingLong', 2); - bandPredictabilityConv = sum(bandPredictability .* spreadingLong', 2); + bandEnergyConv = sum(bandEnergy .* spreadingLong, 2); + bandPredictabilityConv = sum(bandPredictability .* spreadingLong, 2); % Renormalizes values bandPredictabilityConv = bandPredictabilityConv ./ bandEnergyConv; @@ -140,29 +140,29 @@ function SMR = psycho(frameT, frameType, frameTprev1, frameTprev2) qThrN = eps() * 1024 .* 10 .^ (TNSTables.B219a(:, 6) ./ 10); noiseLevel = max(energyThreshold, qThrN); - SMR = bandEnergy ./ noiseLevel'; + SMR = bandEnergy ./ noiseLevel; else % Splits the frame into sub-frames [subFramesT, ~] = buffer(frameT(449:end-448), 256, 128, 'nodelay'); [subFramesTprev1, ~] = buffer(frameTprev1(449:end-448), 256, 128, 'nodelay'); - bandEnergy(SHORT_WINDOW_NUMBER_OF_BANDS) = 0; - bandPredictability(SHORT_WINDOW_NUMBER_OF_BANDS) = 0; + bandEnergy(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; + bandPredictability(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; qThrN = eps() * 128 .* 10 .^ (TNSTables.B219b(:, 6) ./ 10); SMR(SHORT_WINDOW_NUMBER_OF_BANDS, 8) = 0; for subFrameIndex = 1:8 % Applies window to the frames - windowedFrameT = subFramesT(:, subFrameIndex) .* hannShort'; + windowedFrameT = subFramesT(:, subFrameIndex) .* hannShort; if subFrameIndex == 1 - windowedFrameTprev1 = subFramesTprev1(:, 8) .* hannShort'; - windowedFrameTprev2 = subFramesTprev1(:, 7) .* hannShort'; + windowedFrameTprev1 = subFramesTprev1(:, 8) .* hannShort; + windowedFrameTprev2 = subFramesTprev1(:, 7) .* hannShort; elseif subFrameIndex == 2 - windowedFrameTprev1 = subFramesT(:, subFrameIndex - 1) .* hannShort'; - windowedFrameTprev2 = subFramesTprev1(:, 8) .* hannShort'; + windowedFrameTprev1 = subFramesT(:, subFrameIndex - 1) .* hannShort; + windowedFrameTprev2 = subFramesTprev1(:, 8) .* hannShort; else - windowedFrameTprev1 = subFramesT(:, subFrameIndex - 1) .* hannShort'; - windowedFrameTprev2 = subFramesT(:, subFrameIndex - 1) .* hannShort'; + windowedFrameTprev1 = subFramesT(:, subFrameIndex - 1) .* hannShort; + windowedFrameTprev2 = subFramesT(:, subFrameIndex - 1) .* hannShort; end % Calculates the FFT of each frame @@ -226,7 +226,7 @@ function SMR = psycho(frameT, frameType, frameTprev1, frameTprev2) % Calculates the noise level noiseLevel = max(energyThreshold, qThrN); - SMR(:, subFrameIndex) = bandEnergy ./ noiseLevel'; + SMR(:, subFrameIndex) = bandEnergy ./ noiseLevel; end end end