diff --git a/Level_1/AACoder1.m b/Level_1/AACoder1.m index 665c745..ddb6408 100644 --- a/Level_1/AACoder1.m +++ b/Level_1/AACoder1.m @@ -47,15 +47,4 @@ function AACSeq1 = AACoder1(fNameIn) AACSeq1(i + 1).chl.frameF = frameF(:, 1); AACSeq1(i + 1).chr.frameF = frameF(:, 2); end - - if false - [idx,label] = grp2idx(sort(frameTypes)); - hist(idx,unique(idx)); - set(gca,'xTickLabel',label) - - sum(idx(:) == 1) - sum(idx(:) == 2) - sum(idx(:) == 3) - sum(idx(:) == 4) - end end diff --git a/Level_1/SSC.m b/Level_1/SSC.m index 3f59ed8..e53a70f 100644 --- a/Level_1/SSC.m +++ b/Level_1/SSC.m @@ -64,7 +64,7 @@ function frameType = SSC(~, nextFrameT, prevFrameType) % Joins decision for both channels if strcmp(channelFrameType{1}, 'nan') || strcmp(channelFrameType{2}, 'nan') - error('SSC, l[73]: Internal error occurred!') + error('SSC, l[67]: Internal error occurred!') end if strcmp(channelFrameType{1}, 'OLS') frameType = channelFrameType{2}; diff --git a/Level_1/demoAAC1.m b/Level_1/demoAAC1.m index 74bc46b..ed497e6 100644 --- a/Level_1/demoAAC1.m +++ b/Level_1/demoAAC1.m @@ -14,35 +14,8 @@ function SNR = demoAAC1(fNameIn, fNameOut) decodedAudio = iAACoder1(AACSeq1, fNameOut); [audioData, ~] = audioread(fNameIn); - -% figure() -% plot(audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) -% for frame = 1:length(AACSeq1) -% if strcmp(AACSeq1(frame).frameType, 'LSS') || strcmp(AACSeq1(frame).frameType, 'LPS') -% % Add lines -% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]); -% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]); -% % Set properties of lines -% set([h1 h2],'Color','y','LineWidth',2) -% % Add a patch -% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'y') -% elseif strcmp(AACSeq1(frame).frameType, 'ESH') -% % Add lines -% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]); -% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]); -% % Set properties of lines -% set([h1 h2],'Color','r','LineWidth',2) -% % Add a patch -% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'r') -% end -% end -% set(gca,'children',flipud(get(gca,'children'))) -% -% figure() -% plot(audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) snr(audioData(1025:length(decodedAudio)-1024, 2), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) - SNR = 10*log10((sum(audioData(1025:length(decodedAudio)-1024, :)) .^ 2) ./ ... - (sum(audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :)) .^ 2)); + SNR = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :)); end diff --git a/Level_1/filterbank.m b/Level_1/filterbank.m index f1ebdfd..384e82d 100644 --- a/Level_1/filterbank.m +++ b/Level_1/filterbank.m @@ -48,7 +48,7 @@ function frameF = filterbank(frameT, frameType, winType) elseif strcmp(winType, 'SIN') frameT = bsxfun(@times, frameT, sinWindowLong); else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[51]: Unsupported window type input!') end frameF = mdct4(frameT); @@ -62,7 +62,7 @@ function frameF = filterbank(frameT, frameType, winType) frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[65]: Unsupported window type input!') end frameF = mdct4(frameT); @@ -76,7 +76,7 @@ function frameF = filterbank(frameT, frameType, winType) 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!') + error('filterbank, l[79]: Unsupported window type input!') end frameF = mdct4(frameT); diff --git a/Level_1/iFilterbank.m b/Level_1/iFilterbank.m index 57f9456..9734793 100644 --- a/Level_1/iFilterbank.m +++ b/Level_1/iFilterbank.m @@ -50,7 +50,7 @@ function frameT = iFilterbank(frameF, frameType, winType) elseif strcmp(winType, 'SIN') frameT = bsxfun(@times, frameT, sinWindowLong); else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[53]: Unsupported window type input!') end elseif strcmp(frameType, 'LSS') frameT = imdct4(frameF); @@ -64,7 +64,7 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[67]: Unsupported window type input!') end elseif strcmp(frameType, 'LPS') frameT = imdct4(frameF); @@ -78,7 +78,7 @@ function frameT = iFilterbank(frameF, frameType, winType) 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!') + error('filterbank, l[81]: Unsupported window type input!') end elseif strcmp(frameType, 'ESH') for channel=1:2 diff --git a/Level_2/AACoder2.m b/Level_2/AACoder2.m index 21dc7c4..b149c8e 100644 --- a/Level_2/AACoder2.m +++ b/Level_2/AACoder2.m @@ -54,15 +54,4 @@ function AACSeq2 = AACoder2(fNameIn) AACSeq2(i + 1).chl.frameF = frameF(:, 1); AACSeq2(i + 1).chr.frameF = frameF(:, 2); end - - if false - [idx,label] = grp2idx(sort(frameTypes)); - hist(idx,unique(idx)); - set(gca,'xTickLabel',label) - - sum(idx(:) == 1) - sum(idx(:) == 2) - sum(idx(:) == 3) - sum(idx(:) == 4) - end end diff --git a/Level_2/SSC.m b/Level_2/SSC.m index 3f59ed8..e53a70f 100644 --- a/Level_2/SSC.m +++ b/Level_2/SSC.m @@ -64,7 +64,7 @@ function frameType = SSC(~, nextFrameT, prevFrameType) % Joins decision for both channels if strcmp(channelFrameType{1}, 'nan') || strcmp(channelFrameType{2}, 'nan') - error('SSC, l[73]: Internal error occurred!') + error('SSC, l[67]: Internal error occurred!') end if strcmp(channelFrameType{1}, 'OLS') frameType = channelFrameType{2}; diff --git a/Level_2/TNS.m b/Level_2/TNS.m index c76a274..7bdb111 100644 --- a/Level_2/TNS.m +++ b/Level_2/TNS.m @@ -65,7 +65,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) % Filters MDCT coefficients if ~isstable(1, quantizedLinPredCoeff) - error('TNS, l[79]: Inverse filter not stable!'); + error('TNS, l[68]: Inverse filter not stable!'); else TNScoeffs = quantizedLinPredCoeff(2:end)'; frameFout = filter(quantizedLinPredCoeff, 1, frameFin); @@ -110,7 +110,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) % Filters MDCT coefficients if ~isstable(1, quantizedLinPredCoeff) - error('TNS, l[79]: Inverse filter not stable!'); + error('TNS, l[113]: Inverse filter not stable!'); else TNScoeffs((subFrameIndex - 1) * 4 + 1:subFrameIndex * 4) = quantizedLinPredCoeff(2:end); frameFout((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128) = ... diff --git a/Level_2/demoAAC2.m b/Level_2/demoAAC2.m index fc0c42c..f324598 100644 --- a/Level_2/demoAAC2.m +++ b/Level_2/demoAAC2.m @@ -14,35 +14,8 @@ function SNR = demoAAC2(fNameIn, fNameOut) decodedAudio = iAACoder2(AACSeq2, fNameOut); [audioData, ~] = audioread(fNameIn); - -% figure() -% plot(audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) -% for frame = 1:length(AACSeq1) -% if strcmp(AACSeq1(frame).frameType, 'LSS') || strcmp(AACSeq1(frame).frameType, 'LPS') -% % Add lines -% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]); -% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]); -% % Set properties of lines -% set([h1 h2],'Color','y','LineWidth',2) -% % Add a patch -% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'y') -% elseif strcmp(AACSeq1(frame).frameType, 'ESH') -% % Add lines -% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]); -% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]); -% % Set properties of lines -% set([h1 h2],'Color','r','LineWidth',2) -% % Add a patch -% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'r') -% end -% end -% set(gca,'children',flipud(get(gca,'children'))) -% -% figure() -% plot(audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) - + snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) snr(audioData(1025:length(decodedAudio)-1024, 2), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) - SNR = 10*log10((sum(audioData(1025:length(decodedAudio)-1024, :)) .^ 2) ./ ... - (sum(audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :)) .^ 2)); + SNR = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :)); end diff --git a/Level_2/filterbank.m b/Level_2/filterbank.m index f1ebdfd..384e82d 100644 --- a/Level_2/filterbank.m +++ b/Level_2/filterbank.m @@ -48,7 +48,7 @@ function frameF = filterbank(frameT, frameType, winType) elseif strcmp(winType, 'SIN') frameT = bsxfun(@times, frameT, sinWindowLong); else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[51]: Unsupported window type input!') end frameF = mdct4(frameT); @@ -62,7 +62,7 @@ function frameF = filterbank(frameT, frameType, winType) frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[65]: Unsupported window type input!') end frameF = mdct4(frameT); @@ -76,7 +76,7 @@ function frameF = filterbank(frameT, frameType, winType) 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!') + error('filterbank, l[79]: Unsupported window type input!') end frameF = mdct4(frameT); diff --git a/Level_2/iFilterbank.m b/Level_2/iFilterbank.m index 57f9456..9734793 100644 --- a/Level_2/iFilterbank.m +++ b/Level_2/iFilterbank.m @@ -50,7 +50,7 @@ function frameT = iFilterbank(frameF, frameType, winType) elseif strcmp(winType, 'SIN') frameT = bsxfun(@times, frameT, sinWindowLong); else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[53]: Unsupported window type input!') end elseif strcmp(frameType, 'LSS') frameT = imdct4(frameF); @@ -64,7 +64,7 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[67]: Unsupported window type input!') end elseif strcmp(frameType, 'LPS') frameT = imdct4(frameF); @@ -78,7 +78,7 @@ function frameT = iFilterbank(frameF, frameType, winType) 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!') + error('filterbank, l[81]: Unsupported window type input!') end elseif strcmp(frameType, 'ESH') for channel=1:2 diff --git a/Level_3/SSC.m b/Level_3/SSC.m index 3f59ed8..e53a70f 100644 --- a/Level_3/SSC.m +++ b/Level_3/SSC.m @@ -64,7 +64,7 @@ function frameType = SSC(~, nextFrameT, prevFrameType) % Joins decision for both channels if strcmp(channelFrameType{1}, 'nan') || strcmp(channelFrameType{2}, 'nan') - error('SSC, l[73]: Internal error occurred!') + error('SSC, l[67]: Internal error occurred!') end if strcmp(channelFrameType{1}, 'OLS') frameType = channelFrameType{2}; diff --git a/Level_3/TNS.m b/Level_3/TNS.m index c76a274..7bdb111 100644 --- a/Level_3/TNS.m +++ b/Level_3/TNS.m @@ -65,7 +65,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) % Filters MDCT coefficients if ~isstable(1, quantizedLinPredCoeff) - error('TNS, l[79]: Inverse filter not stable!'); + error('TNS, l[68]: Inverse filter not stable!'); else TNScoeffs = quantizedLinPredCoeff(2:end)'; frameFout = filter(quantizedLinPredCoeff, 1, frameFin); @@ -110,7 +110,7 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType) % Filters MDCT coefficients if ~isstable(1, quantizedLinPredCoeff) - error('TNS, l[79]: Inverse filter not stable!'); + error('TNS, l[113]: Inverse filter not stable!'); else TNScoeffs((subFrameIndex - 1) * 4 + 1:subFrameIndex * 4) = quantizedLinPredCoeff(2:end); frameFout((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128) = ... diff --git a/Level_3/demoAAC3.m b/Level_3/demoAAC3.m index f437a75..2a65ede 100644 --- a/Level_3/demoAAC3.m +++ b/Level_3/demoAAC3.m @@ -20,34 +20,7 @@ function [SNR, bitrate, compression] = demoAAC3(fNameIn, fNameOut, frameAACoded) [audioData, ~] = audioread(fNameIn); -% figure() -% plot(audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) -% for frame = 1:length(AACSeq3) -% if strcmp(AACSeq3(frame).frameType, 'LSS') || strcmp(AACSeq3(frame).frameType, 'LPS') -% % Add lines -% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]); -% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]); -% % Set properties of lines -% set([h1 h2],'Color','y','LineWidth',2) -% % Add a patch -% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'y') -% elseif strcmp(AACSeq3(frame).frameType, 'ESH') -% % Add lines -% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]); -% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]); -% % Set properties of lines -% set([h1 h2],'Color','r','LineWidth',2) -% % Add a patch -% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'r') -% end -% end -% set(gca,'children',flipud(get(gca,'children'))) -% -% figure() -% plot(audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) - snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) snr(audioData(1025:length(decodedAudio)-1024, 2), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) - SNR = 10*log10((sum(audioData(1025:length(decodedAudio)-1024, :)) .^ 2) ./ ... - (sum(audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :)) .^ 2)); + SNR = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, :)); end diff --git a/Level_3/encoded.mat b/Level_3/encoded.mat index 89118ea..bfa719c 100644 Binary files a/Level_3/encoded.mat and b/Level_3/encoded.mat differ diff --git a/Level_3/filterbank.m b/Level_3/filterbank.m index f1ebdfd..384e82d 100644 --- a/Level_3/filterbank.m +++ b/Level_3/filterbank.m @@ -48,7 +48,7 @@ function frameF = filterbank(frameT, frameType, winType) elseif strcmp(winType, 'SIN') frameT = bsxfun(@times, frameT, sinWindowLong); else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[51]: Unsupported window type input!') end frameF = mdct4(frameT); @@ -62,7 +62,7 @@ function frameF = filterbank(frameT, frameType, winType) frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[65]: Unsupported window type input!') end frameF = mdct4(frameT); @@ -76,7 +76,7 @@ function frameF = filterbank(frameT, frameType, winType) 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!') + error('filterbank, l[79]: Unsupported window type input!') end frameF = mdct4(frameT); diff --git a/Level_3/iFilterbank.m b/Level_3/iFilterbank.m index 57f9456..9734793 100644 --- a/Level_3/iFilterbank.m +++ b/Level_3/iFilterbank.m @@ -50,7 +50,7 @@ function frameT = iFilterbank(frameF, frameType, winType) elseif strcmp(winType, 'SIN') frameT = bsxfun(@times, frameT, sinWindowLong); else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[53]: Unsupported window type input!') end elseif strcmp(frameType, 'LSS') frameT = imdct4(frameF); @@ -64,7 +64,7 @@ function frameT = iFilterbank(frameF, frameType, winType) frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)); frameT(1601:end, :) = 0; else - error('filterbank, l[20]: Unsupported window type input!') + error('filterbank, l[67]: Unsupported window type input!') end elseif strcmp(frameType, 'LPS') frameT = imdct4(frameF); @@ -78,7 +78,7 @@ function frameT = iFilterbank(frameF, frameType, winType) 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!') + error('filterbank, l[81]: Unsupported window type input!') end elseif strcmp(frameType, 'ESH') for channel=1:2