MP3 PQF模块 matlab实现

########################################

#     WAV_PQF.m

########################################

clc;
clear;
FRAME_LEN = 384;
FRAME_NUM = 1200;
ENC_BITRATE = 192000;
%[y,Fs,bits] = wavread('Out_bass.wav',FRAME_LEN*FRAME_NUM*2);
%[y,Fs,bits] = wavread('勇闯夺命岛.wav',FRAME_LEN*FRAME_NUM*2);
[y,Fs,bits] = wavread('1.wav',FRAME_LEN*FRAME_NUM*2);
scale = 2^(bits-1);

ch0 = y(:,1);
%ch1 = y(:,2);
C = Table_analysis_window';
D = Table_synthesis_window';
X = zeros(512,1);
V = zeros(1024,1);
S = zeros(12,32);

bit_per_frame = fix(ENC_BITRATE*12/Fs)*32;
BIT_HDR = 32;
BIT_CRC = 0;
SBLIMIT = 32;
jsbound = 32;
nch = 1;
bit_ball = 4 * ( (jsbound * nch) + (SBLIMIT-jsbound) );

for j=1:FRAME_NUM
fprintf(1,'**************************frame_num =%d*****************************\n',j);
if j == 50
bk =1;
end
x0 = ch0((j-1)*FRAME_LEN + 1:j*FRAME_LEN);
% x1 = ch1((j-1)*FRAME_LEN + 1:j*FRAME_LEN);

for i = 0:11,
[S(i+1,:) X] = pqf(x0, (32 * i + 1), C, X);
end
[scf scfcode]= Scale_factors(S);
for i = 1:32,
Qspl(:,i) = S(:,i)./scf(i);
end



descf = DeScale_factors(scfcode);
for i = 1:32,
DeS(:,i) = Qspl(:,i)*descf(i);
end
for i = 1:12,
freq = DeS(i,:);
[T V] = ipqf(freq, D, V);
x2((32 * (i - 1) + 1:32 * i),1) = T;
end
ch2((j-1)*FRAME_LEN + 1:j*FRAME_LEN) = x2;
% subplot(2,1,1); plot(x0);
% subplot(2,1,2); plot(x2);
% saveas(gcf,['angle' num2str(j) '.jpg']);
end
wavwrite(ch2,Fs,'Out.wav');

 

###################################################################

#分析窗

###################################################################

function C = Table_analysis_window
%C = Table_analysis_window
%
% Initialise the analysis window used in the subband analysis.
% The C coefficients are given in [1, pp. 68--69].
%
% See also Analysis_subband_filter

% Author: Fabien A.P. Petitcolas
% Computer Laboratory
% University of Cambridge
% $Id: Table_analysis_window.m,v 1.2 1998-06-22 17:47:56+01 fapp2 Exp $

% References:
% [1] Information technology -- Coding of moving pictures and associated
% audio for digital storage media at up to 1,5 Mbits/s -- Part3: audio.
% British standard. BSI, London. October 1993. Implementation of ISO/IEC
% 11172-3:1993. BSI, London. First edition 1993-08-01.
%
% Legal notice:
% This computer program is based on ISO/IEC 11172-3:1993, Information
% technology -- Coding of moving pictures and associated audio for digital
% storage media at up to about 1,5 Mbit/s -- Part 3: Audio, with the
% permission of ISO. Copies of this standards can be purchased from the
% British Standards Institution, 389 Chiswick High Road, GB-London W4 4AL,
% Telephone:+ 44 181 996 90 00, Telefax:+ 44 181 996 74 00 or from ISO,
% postal box 56, CH-1211 Geneva 20, Telephone +41 22 749 0111, Telefax
% +4122 734 1079. Copyright remains with ISO.
%-------------------------------------------------------------------------------

% Matlab starts indices at one so we need a fix for C(0) = 0.0;
C( 1)=-0.000000477; C( 2)=-0.000000477; C( 3)=-0.000000477 ;
C( 4)=-0.000000477; C( 5)=-0.000000477; C( 6)=-0.000000477; C( 7)=-0.000000954 ;
C( 8)=-0.000000954; C( 9)=-0.000000954; C( 10)=-0.000000954; C( 11)=-0.000001431 ;
C( 12)=-0.000001431; C( 13)=-0.000001907; C( 14)=-0.000001907; C( 15)=-0.000002384 ;
C( 16)=-0.000002384; C( 17)=-0.000002861; C( 18)=-0.000003338; C( 19)=-0.000003338 ;
C( 20)=-0.000003815; C( 21)=-0.000004292; C( 22)=-0.000004768; C( 23)=-0.000005245 ;
C( 24)=-0.000006199; C( 25)=-0.000006676; C( 26)=-0.000007629; C( 27)=-0.000008106 ;
C( 28)=-0.000009060; C( 29)=-0.000010014; C( 30)=-0.000011444; C( 31)=-0.000012398 ;
C( 32)=-0.000013828; C( 33)=-0.000014782; C( 34)=-0.000016689; C( 35)=-0.000018120 ;
C( 36)=-0.000019550; C( 37)=-0.000021458; C( 38)=-0.000023365; C( 39)=-0.000025272 ;
C( 40)=-0.000027657; C( 41)=-0.000030041; C( 42)=-0.000032425; C( 43)=-0.000034809 ;
C( 44)=-0.000037670; C( 45)=-0.000040531; C( 46)=-0.000043392; C( 47)=-0.000046253 ;
C( 48)=-0.000049591; C( 49)=-0.000052929; C( 50)=-0.000055790; C( 51)=-0.000059605 ;
C( 52)=-0.000062943; C( 53)=-0.000066280; C( 54)=-0.000070095; C( 55)=-0.000073433 ;
C( 56)=-0.000076771; C( 57)=-0.000080585; C( 58)=-0.000083923; C( 59)=-0.000087261 ;
C( 60)=-0.000090599; C( 61)=-0.000093460; C( 62)=-0.000096321; C( 63)=-0.000099182 ;
C( 64)= 0.000101566; C( 65)= 0.000103951; C( 66)= 0.000105858; C( 67)= 0.000107288 ;
C( 68)= 0.000108242; C( 69)= 0.000108719; C( 70)= 0.000108719; C( 71)= 0.000108242 ;
C( 72)= 0.000106812; C( 73)= 0.000105381; C( 74)= 0.000102520; C( 75)= 0.000099182 ;
C( 76)= 0.000095367; C( 77)= 0.000090122; C( 78)= 0.000084400; C( 79)= 0.000077724 ;
C( 80)= 0.000069618; C( 81)= 0.000060558; C( 82)= 0.000050545; C( 83)= 0.000039577 ;
C( 84)= 0.000027180; C( 85)= 0.000013828; C( 86)=-0.000000954; C( 87)=-0.000017166 ;
C( 88)=-0.000034332; C( 89)=-0.000052929; C( 90)=-0.000072956; C( 91)=-0.000093937 ;
C( 92)=-0.000116348; C( 93)=-0.000140190; C( 94)=-0.000165462; C( 95)=-0.000191212 ;
C( 96)=-0.000218868; C( 97)=-0.000247478; C( 98)=-0.000277042; C( 99)=-0.000307560 ;
C(100)=-0.000339031; C(101)=-0.000371456; C(102)=-0.000404358; C(103)=-0.000438213 ;
C(104)=-0.000472546; C(105)=-0.000507355; C(106)=-0.000542164; C(107)=-0.000576973 ;
C(108)=-0.000611782; C(109)=-0.000646591; C(110)=-0.000680923; C(111)=-0.000714302 ;
C(112)=-0.000747204; C(113)=-0.000779152; C(114)=-0.000809669; C(115)=-0.000838757 ;
C(116)=-0.000866413; C(117)=-0.000891685; C(118)=-0.000915051; C(119)=-0.000935555 ;
C(120)=-0.000954151; C(121)=-0.000968933; C(122)=-0.000980854; C(123)=-0.000989437 ;
C(124)=-0.000994205; C(125)=-0.000995159; C(126)=-0.000991821; C(127)=-0.000983715 ;
C(128)= 0.000971317; C(129)= 0.000953674; C(130)= 0.000930786; C(131)= 0.000902653 ;
C(132)= 0.000868797; C(133)= 0.000829220; C(134)= 0.000783920; C(135)= 0.000731945 ;
C(136)= 0.000674248; C(137)= 0.000610352; C(138)= 0.000539303; C(139)= 0.000462532 ;
C(140)= 0.000378609; C(141)= 0.000288486; C(142)= 0.000191689; C(143)= 0.000088215 ;
C(144)=-0.000021458; C(145)=-0.000137329; C(146)=-0.000259876; C(147)=-0.000388145 ;
C(148)=-0.000522137; C(149)=-0.000661850; C(150)=-0.000806808; C(151)=-0.000956535 ;
C(152)=-0.001111031; C(153)=-0.001269817; C(154)=-0.001432419; C(155)=-0.001597881 ;
C(156)=-0.001766682; C(157)=-0.001937389; C(158)=-0.002110004; C(159)=-0.002283096 ;
C(160)=-0.002457142; C(161)=-0.002630711; C(162)=-0.002803326; C(163)=-0.002974033 ;
C(164)=-0.003141880; C(165)=-0.003306866; C(166)=-0.003467083; C(167)=-0.003622532 ;
C(168)=-0.003771782; C(169)=-0.003914356; C(170)=-0.004048824; C(171)=-0.004174709 ;
C(172)=-0.004290581; C(173)=-0.004395962; C(174)=-0.004489899; C(175)=-0.004570484 ;
C(176)=-0.004638195; C(177)=-0.004691124; C(178)=-0.004728317; C(179)=-0.004748821 ;
C(180)=-0.004752159; C(181)=-0.004737377; C(182)=-0.004703045; C(183)=-0.004649162 ;
C(184)=-0.004573822; C(185)=-0.004477024; C(186)=-0.004357815; C(187)=-0.004215240 ;
C(188)=-0.004049301; C(189)=-0.003858566; C(190)=-0.003643036; C(191)=-0.003401756 ;
C(192)= 0.003134727; C(193)= 0.002841473; C(194)= 0.002521515; C(195)= 0.002174854 ;
C(196)= 0.001800537; C(197)= 0.001399517; C(198)= 0.000971317; C(199)= 0.000515938 ;
C(200)= 0.000033379; C(201)=-0.000475883; C(202)=-0.001011848; C(203)=-0.001573563 ;
C(204)=-0.002161503; C(205)=-0.002774239; C(206)=-0.003411293; C(207)=-0.004072189 ;
C(208)=-0.004756451; C(209)=-0.005462170; C(210)=-0.006189346; C(211)=-0.006937027 ;
C(212)=-0.007703304; C(213)=-0.008487225; C(214)=-0.009287834; C(215)=-0.010103703 ;
C(216)=-0.010933399; C(217)=-0.011775017; C(218)=-0.012627602; C(219)=-0.013489246 ;
C(220)=-0.014358521; C(221)=-0.015233517; C(222)=-0.016112804; C(223)=-0.016994476 ;
C(224)=-0.017876148; C(225)=-0.018756866; C(226)=-0.019634247; C(227)=-0.020506859 ;
C(228)=-0.021372318; C(229)=-0.022228718; C(230)=-0.023074150; C(231)=-0.023907185 ;
C(232)=-0.024725437; C(233)=-0.025527000; C(234)=-0.026310921; C(235)=-0.027073860 ;
C(236)=-0.027815342; C(237)=-0.028532982; C(238)=-0.029224873; C(239)=-0.029890060 ;
C(240)=-0.030526638; C(241)=-0.031132698; C(242)=-0.031706810; C(243)=-0.032248020 ;
C(244)=-0.032754898; C(245)=-0.033225536; C(246)=-0.033659935; C(247)=-0.034055710 ;
C(248)=-0.034412861; C(249)=-0.034730434; C(250)=-0.035007000; C(251)=-0.035242081 ;
C(252)=-0.035435200; C(253)=-0.035586357; C(254)=-0.035694122; C(255)=-0.035758972 ;
C(256)= 0.035780907; C(257)= 0.035758972; C(258)= 0.035694122; C(259)= 0.035586357 ;
C(260)= 0.035435200; C(261)= 0.035242081; C(262)= 0.035007000; C(263)= 0.034730434 ;
C(264)= 0.034412861; C(265)= 0.034055710; C(266)= 0.033659935; C(267)= 0.033225536 ;
C(268)= 0.032754898; C(269)= 0.032248020; C(270)= 0.031706810; C(271)= 0.031132698 ;
C(272)= 0.030526638; C(273)= 0.029890060; C(274)= 0.029224873; C(275)= 0.028532982 ;
C(276)= 0.027815342; C(277)= 0.027073860; C(278)= 0.026310921; C(279)= 0.025527000 ;
C(280)= 0.024725437; C(281)= 0.023907185; C(282)= 0.023074150; C(283)= 0.022228718 ;
C(284)= 0.021372318; C(285)= 0.020506859; C(286)= 0.019634247; C(287)= 0.018756866 ;
C(288)= 0.017876148; C(289)= 0.016994476; C(290)= 0.016112804; C(291)= 0.015233517 ;
C(292)= 0.014358521; C(293)= 0.013489246; C(294)= 0.012627602; C(295)= 0.011775017 ;
C(296)= 0.010933399; C(297)= 0.010103703; C(298)= 0.009287834; C(299)= 0.008487225 ;
C(300)= 0.007703304; C(301)= 0.006937027; C(302)= 0.006189346; C(303)= 0.005462170 ;
C(304)= 0.004756451; C(305)= 0.004072189; C(306)= 0.003411293; C(307)= 0.002774239 ;
C(308)= 0.002161503; C(309)= 0.001573563; C(310)= 0.001011848; C(311)= 0.000475883 ;
C(312)=-0.000033379; C(313)=-0.000515938; C(314)=-0.000971317; C(315)=-0.001399517 ;
C(316)=-0.001800537; C(317)=-0.002174854; C(318)=-0.002521515; C(319)=-0.002841473 ;
C(320)= 0.003134727; C(321)= 0.003401756; C(322)= 0.003643036; C(323)= 0.003858566 ;
C(324)= 0.004049301; C(325)= 0.004215240; C(326)= 0.004357815; C(327)= 0.004477024 ;
C(328)= 0.004573822; C(329)= 0.004649162; C(330)= 0.004703045; C(331)= 0.004737377 ;
C(332)= 0.004752159; C(333)= 0.004748821; C(334)= 0.004728317; C(335)= 0.004691124 ;
C(336)= 0.004638195; C(337)= 0.004570484; C(338)= 0.004489899; C(339)= 0.004395962 ;
C(340)= 0.004290581; C(341)= 0.004174709; C(342)= 0.004048824; C(343)= 0.003914356 ;
C(344)= 0.003771782; C(345)= 0.003622532; C(346)= 0.003467083; C(347)= 0.003306866 ;
C(348)= 0.003141880; C(349)= 0.002974033; C(350)= 0.002803326; C(351)= 0.002630711 ;
C(352)= 0.002457142; C(353)= 0.002283096; C(354)= 0.002110004; C(355)= 0.001937389 ;
C(356)= 0.001766682; C(357)= 0.001597881; C(358)= 0.001432419; C(359)= 0.001269817 ;
C(360)= 0.001111031; C(361)= 0.000956535; C(362)= 0.000806808; C(363)= 0.000661850 ;
C(364)= 0.000522137; C(365)= 0.000388145; C(366)= 0.000259876; C(367)= 0.000137329 ;
C(368)= 0.000021458; C(369)=-0.000088215; C(370)=-0.000191689; C(371)=-0.000288486 ;
C(372)=-0.000378609; C(373)=-0.000462532; C(374)=-0.000539303; C(375)=-0.000610352 ;
C(376)=-0.000674248; C(377)=-0.000731945; C(378)=-0.000783920; C(379)=-0.000829220 ;
C(380)=-0.000868797; C(381)=-0.000902653; C(382)=-0.000930786; C(383)=-0.000953674 ;
C(384)= 0.000971317; C(385)= 0.000983715; C(386)= 0.000991821; C(387)= 0.000995159 ;
C(388)= 0.000994205; C(389)= 0.000989437; C(390)= 0.000980854; C(391)= 0.000968933 ;
C(392)= 0.000954151; C(393)= 0.000935555; C(394)= 0.000915051; C(395)= 0.000891685 ;
C(396)= 0.000866413; C(397)= 0.000838757; C(398)= 0.000809669; C(399)= 0.000779152 ;
C(400)= 0.000747204; C(401)= 0.000714302; C(402)= 0.000680923; C(403)= 0.000646591 ;
C(404)= 0.000611782; C(405)= 0.000576973; C(406)= 0.000542164; C(407)= 0.000507355 ;
C(408)= 0.000472546; C(409)= 0.000438213; C(410)= 0.000404358; C(411)= 0.000371456 ;
C(412)= 0.000339031; C(413)= 0.000307560; C(414)= 0.000277042; C(415)= 0.000247478 ;
C(416)= 0.000218868; C(417)= 0.000191212; C(418)= 0.000165462; C(419)= 0.000140190 ;
C(420)= 0.000116348; C(421)= 0.000093937; C(422)= 0.000072956; C(423)= 0.000052929 ;
C(424)= 0.000034332; C(425)= 0.000017166; C(426)= 0.000000954; C(427)=-0.000013828 ;
C(428)=-0.000027180; C(429)=-0.000039577; C(430)=-0.000050545; C(431)=-0.000060558 ;
C(432)=-0.000069618; C(433)=-0.000077724; C(434)=-0.000084400; C(435)=-0.000090122 ;
C(436)=-0.000095367; C(437)=-0.000099182; C(438)=-0.000102520; C(439)=-0.000105381 ;
C(440)=-0.000106812; C(441)=-0.000108242; C(442)=-0.000108719; C(443)=-0.000108719 ;
C(444)=-0.000108242; C(445)=-0.000107288; C(446)=-0.000105858; C(447)=-0.000103951 ;
C(448)= 0.000101566; C(449)= 0.000099182; C(450)= 0.000096321; C(451)= 0.000093460 ;
C(452)= 0.000090599; C(453)= 0.000087261; C(454)= 0.000083923; C(455)= 0.000080585 ;
C(456)= 0.000076771; C(457)= 0.000073433; C(458)= 0.000070095; C(459)= 0.000066280 ;
C(460)= 0.000062943; C(461)= 0.000059605; C(462)= 0.000055790; C(463)= 0.000052929 ;
C(464)= 0.000049591; C(465)= 0.000046253; C(466)= 0.000043392; C(467)= 0.000040531 ;
C(468)= 0.000037670; C(469)= 0.000034809; C(470)= 0.000032425; C(471)= 0.000030041 ;
C(472)= 0.000027657; C(473)= 0.000025272; C(474)= 0.000023365; C(475)= 0.000021458 ;
C(476)= 0.000019550; C(477)= 0.000018120; C(478)= 0.000016689; C(479)= 0.000014782 ;
C(480)= 0.000013828; C(481)= 0.000012398; C(482)= 0.000011444; C(483)= 0.000010014 ;
C(484)= 0.000009060; C(485)= 0.000008106; C(486)= 0.000007629; C(487)= 0.000006676 ;
C(488)= 0.000006199; C(489)= 0.000005245; C(490)= 0.000004768; C(491)= 0.000004292 ;
C(492)= 0.000003815; C(493)= 0.000003338; C(494)= 0.000003338; C(495)= 0.000002861 ;
C(496)= 0.000002384; C(497)= 0.000002384; C(498)= 0.000001907; C(499)= 0.000001907 ;
C(500)= 0.000001431; C(501)= 0.000001431; C(502)= 0.000000954; C(503)= 0.000000954 ;
C(504)= 0.000000954; C(505)= 0.000000954; C(506)= 0.000000477; C(507)= 0.000000477 ;
C(508)= 0.000000477; C(509)= 0.000000477; C(510)= 0.000000477; C(511)= 0.000000477 ;

% Fix: insert the null coefficient at the beginning
C = [0.0 C];

% Contrary to [1, pp. 76], here the most recent sample will have a higher
% index than the first one.
% C = flipud(C(:));

 

 

#####################################

#Scale_factors

###############################

function [scf scfcode]= Scale_factors(S)
%scf = Scale_factors(S)
% For each subband S(i, :), the maximum of the absolute value of 12
% samples S(i, 1) ... S(i, 12) is determined. The next largest value of
% the scale factor in the scale factor table [1, pp. 45] and [1, pp 70]
% is chosen.
%
% See also

% Author: Fabien A. P. Petitcolas
% Computer Laboratory
% University of Cambridge
%
% Copyright (c) 1998--2001 by Fabien A. P. Petitcolas
% $Header: /Matlab MPEG/Scale_factors.m 3 7/07/01 1:27 Fabienpe $
% $Id: Scale_factors.m,v 1.3 1998-06-24 10:20:22+01 fapp2 Exp $

% References:
% [1] Information technology -- Coding of moving pictures and associated
% audio for digital storage media at up to 1,5 Mbits/s -- Part3: audio.
% British standard. BSI, London. October 1993. Implementation of ISO/IEC
% 11172-3:1993. BSI, London. First edition 1993-08-01.
%
% Legal notice:
% This computer program is based on ISO/IEC 11172-3:1993, Information
% technology -- Coding of moving pictures and associated audio for digital
% storage media at up to about 1,5 Mbit/s -- Part 3: Audio, with the
% permission of ISO. Copies of this standards can be purchased from the
% British Standards Institution, 389 Chiswick High Road, GB-London W4 4AL,
% Telephone:+ 44 181 996 90 00, Telefax:+ 44 181 996 74 00 or from ISO,
% postal box 56, CH-1211 Geneva 20, Telephone +41 22 749 0111, Telefax
% +4122 734 1079. Copyright remains with ISO.
%-------------------------------------------------------------------------------

Table_scf = [
2.00000000000000; 1.58740105196820; 1.25992104989487; 1.00000000000000;
0.79370052598410; 0.62996052494744; 0.50000000000000; 0.39685026299205;
0.31498026247372; 0.25000000000000; 0.19842513149602; 0.15749013123686;
0.12500000000000; 0.09921256574801; 0.07874506561843; 0.06250000000000;
0.04960628287401; 0.03937253280921; 0.03125000000000; 0.02480314143700;
0.01968626640461; 0.01562500000000; 0.01240157071850; 0.00984313320230;
0.00781250000000; 0.00620078535925; 0.00492156660115; 0.00390625000000;
0.00310039267963; 0.00246078330058; 0.00195312500000; 0.00155019633981;
0.00123039165029; 0.00097656250000; 0.00077509816991; 0.00061519582514;
0.00048828125000; 0.00038754908495; 0.00030759791257; 0.00024414062500;
0.00019377454248; 0.00015379895629; 0.00012207031250; 0.00009688727124;
0.00007689947814; 0.00006103515625; 0.00004844363562; 0.00003844973907;
0.00003051757813; 0.00002422181781; 0.00001922486954; 0.00001525878906;
0.00001211090890; 0.00000961243477; 0.00000762939453; 0.00000605545445;
0.00000480621738; 0.00000381469727; 0.00000302772723; 0.00000240310869;
0.00000190734863; 0.00000151386361; 0.00000120155435; 1E-20
];

N = length(Table_scf);

for i = 1:32,
si_min = max(abs(S(:, i)));
if (si_min > Table_scf(1))
% This usually happen when the input signal has values
% greater than one.
disp('Warning: cannot find scale factor.');
scf(i) = Table_scf(1);
scfcode(i) = 1;
else
j = 0;
while (j < N & si_min > Table_scf(N - j))
j = j + 1;
end
scf(i) = Table_scf(N - j);
scfcode(i) = N-j;
end
end

###############################

#综合窗

###############################

function D = Table_synthesis_window
D( 1)=-0.000015259; D( 2)=-0.000015259; D( 3)=-0.000015259;
D( 4)=-0.000015259; D( 5)=-0.000015259; D( 6)=-0.000015259; D( 7)=-0.000030518;
D( 8)=-0.000030518; D( 9)=-0.000030518; D( 10)=-0.000030518; D( 11)=-0.000045776;
D( 12)=-0.000045776; D( 13)=-0.000061035; D( 14)=-0.000061035; D( 15)=-0.000076294;
D( 16)=-0.000076294; D( 17)=-0.000091553; D( 18)=-0.000106812; D( 19)=-0.000106812;
D( 20)=-0.000122070; D( 21)=-0.000137329; D( 22)=-0.000152588; D( 23)=-0.000167847;
D( 24)=-0.000198364; D( 25)=-0.000213623; D( 26)=-0.000244141; D( 27)=-0.000259399;
D( 28)=-0.000289917; D( 29)=-0.000320435; D( 30)=-0.000366211; D( 31)=-0.000396729;
D( 32)=-0.000442505; D( 33)=-0.000473022; D( 34)=-0.000534058; D( 35)=-0.000579834;
D( 36)=-0.000625610; D( 37)=-0.000686646; D( 38)=-0.000747681; D( 39)=-0.000808716;
D( 40)=-0.000885010; D( 41)=-0.000961304; D( 42)=-0.001037598; D( 43)=-0.001113892;
D( 44)=-0.001205444; D( 45)=-0.001296997; D( 46)=-0.001388550; D( 47)=-0.001480103;
D( 48)=-0.001586914; D( 49)=-0.001693726; D( 50)=-0.001785278; D( 51)=-0.001907349;
D( 52)=-0.002014160; D( 53)=-0.002120972; D( 54)=-0.002243042; D( 55)=-0.002349854;
D( 56)=-0.002456665; D( 57)=-0.002578735; D( 58)=-0.002685547; D( 59)=-0.002792358;
D( 60)=-0.002899170; D( 61)=-0.002990723; D( 62)=-0.003082275; D( 63)=-0.003173828;
D( 64)= 0.003250122; D( 65)= 0.003326416; D( 66)= 0.003387451; D( 67)= 0.003433228;
D( 68)= 0.003463745; D( 69)= 0.003479004; D( 70)= 0.003479004; D( 71)= 0.003463745;
D( 72)= 0.003417969; D( 73)= 0.003372192; D( 74)= 0.003280640; D( 75)= 0.003173828;
D( 76)= 0.003051758; D( 77)= 0.002883911; D( 78)= 0.002700806; D( 79)= 0.002487183;
D( 80)= 0.002227783; D( 81)= 0.001937866; D( 82)= 0.001617432; D( 83)= 0.001266479;
D( 84)= 0.000869751; D( 85)= 0.000442505; D( 86)=-0.000030518; D( 87)=-0.000549316;
D( 88)=-0.001098633; D( 89)=-0.001693726; D( 90)=-0.002334595; D( 91)=-0.003005981;
D( 92)=-0.003723145; D( 93)=-0.004486084; D( 94)=-0.005294800; D( 95)=-0.006118774;
D( 96)=-0.007003784; D( 97)=-0.007919312; D( 98)=-0.008865356; D( 99)=-0.009841919;
D(100)=-0.010848999; D(101)=-0.011886597; D(102)=-0.012939453; D(103)=-0.014022827;
D(104)=-0.015121460; D(105)=-0.016235352; D(106)=-0.017349243; D(107)=-0.018463135;
D(108)=-0.019577026; D(109)=-0.020690918; D(110)=-0.021789551; D(111)=-0.022857666;
D(112)=-0.023910522; D(113)=-0.024932861; D(114)=-0.025909424; D(115)=-0.026840210;
D(116)=-0.027725220; D(117)=-0.028533936; D(118)=-0.029281616; D(119)=-0.029937744;
D(120)=-0.030532837; D(121)=-0.031005859; D(122)=-0.031387329; D(123)=-0.031661987;
D(124)=-0.031814575; D(125)=-0.031845093; D(126)=-0.031738281; D(127)=-0.031478882;
D(128)= 0.031082153; D(129)= 0.030517578; D(130)= 0.029785156; D(131)= 0.028884888;
D(132)= 0.027801514; D(133)= 0.026535034; D(134)= 0.025085449; D(135)= 0.023422241;
D(136)= 0.021575928; D(137)= 0.019531250; D(138)= 0.017257690; D(139)= 0.014801025;
D(140)= 0.012115479; D(141)= 0.009231567; D(142)= 0.006134033; D(143)= 0.002822876;
D(144)=-0.000686646; D(145)=-0.004394531; D(146)=-0.008316040; D(147)=-0.012420654;
D(148)=-0.016708374; D(149)=-0.021179199; D(150)=-0.025817871; D(151)=-0.030609131;
D(152)=-0.035552979; D(153)=-0.040634155; D(154)=-0.045837402; D(155)=-0.051132202;
D(156)=-0.056533813; D(157)=-0.061996460; D(158)=-0.067520142; D(159)=-0.073059082;
D(160)=-0.078628540; D(161)=-0.084182739; D(162)=-0.089706421; D(163)=-0.095169067;
D(164)=-0.100540161; D(165)=-0.105819702; D(166)=-0.110946655; D(167)=-0.115921021;
D(168)=-0.120697021; D(169)=-0.125259399; D(170)=-0.129562378; D(171)=-0.133590698;
D(172)=-0.137298584; D(173)=-0.140670776; D(174)=-0.143676758; D(175)=-0.146255493;
D(176)=-0.148422241; D(177)=-0.150115967; D(178)=-0.151306152; D(179)=-0.151962280;
D(180)=-0.152069092; D(181)=-0.151596069; D(182)=-0.150497437; D(183)=-0.148773193;
D(184)=-0.146362305; D(185)=-0.143264771; D(186)=-0.139450073; D(187)=-0.134887695;
D(188)=-0.129577637; D(189)=-0.123474121; D(190)=-0.116577148; D(191)=-0.108856201;
D(192)= 0.100311279; D(193)= 0.090927124; D(194)= 0.080688477; D(195)= 0.069595337;
D(196)= 0.057617187; D(197)= 0.044784546; D(198)= 0.031082153; D(199)= 0.016510010;
D(200)= 0.001068115; D(201)=-0.015228271; D(202)=-0.032379150; D(203)=-0.050354004;
D(204)=-0.069168091; D(205)=-0.088775635; D(206)=-0.109161377; D(207)=-0.130310059;
D(208)=-0.152206421; D(209)=-0.174789429; D(210)=-0.198059082; D(211)=-0.221984863;
D(212)=-0.246505737; D(213)=-0.271591187; D(214)=-0.297210693; D(215)=-0.323318481;
D(216)=-0.349868774; D(217)=-0.376800537; D(218)=-0.404083252; D(219)=-0.431655884;
D(220)=-0.459472656; D(221)=-0.487472534; D(222)=-0.515609741; D(223)=-0.543823242;
D(224)=-0.572036743; D(225)=-0.600219727; D(226)=-0.628295898; D(227)=-0.656219482;
D(228)=-0.683914185; D(229)=-0.711318970; D(230)=-0.738372803; D(231)=-0.765029907;
D(232)=-0.791213989; D(233)=-0.816864014; D(234)=-0.841949463; D(235)=-0.866363525;
D(236)=-0.890090942; D(237)=-0.913055420; D(238)=-0.935195923; D(239)=-0.956481934;
D(240)=-0.976852417; D(241)=-0.996246338; D(242)=-1.014617920; D(243)=-1.031936646;
D(244)=-1.048156738; D(245)=-1.063217163; D(246)=-1.077117920; D(247)=-1.089782715;
D(248)=-1.101211548; D(249)=-1.111373901; D(250)=-1.120223999; D(251)=-1.127746582;
D(252)=-1.133926392; D(253)=-1.138763428; D(254)=-1.142211914; D(255)=-1.144287109;
D(256)= 1.144989014; D(257)= 1.144287109; D(258)= 1.142211914; D(259)= 1.138763428;
D(260)= 1.133926392; D(261)= 1.127746582; D(262)= 1.120223999; D(263)= 1.111373901;
D(264)= 1.101211548; D(265)= 1.089782715; D(266)= 1.077117920; D(267)= 1.063217163;
D(268)= 1.048156738; D(269)= 1.031936646; D(270)= 1.014617920; D(271)= 0.996246338;
D(272)= 0.976852417; D(273)= 0.956481934; D(274)= 0.935195923; D(275)= 0.913055420;
D(276)= 0.890090942; D(277)= 0.866363525; D(278)= 0.841949463; D(279)= 0.816864014;
D(280)= 0.791213989; D(281)= 0.765029907; D(282)= 0.738372803; D(283)= 0.711318970;
D(284)= 0.683914185; D(285)= 0.656219482; D(286)= 0.628295898; D(287)= 0.600219727;
D(288)= 0.572036743; D(289)= 0.543823242; D(290)= 0.515609741; D(291)= 0.487472534;
D(292)= 0.459472656; D(293)= 0.431655884; D(294)= 0.404083252; D(295)= 0.376800537;
D(296)= 0.349868774; D(297)= 0.323318481; D(298)= 0.297210693; D(299)= 0.271591187;
D(300)= 0.246505737; D(301)= 0.221984863; D(302)= 0.198059082; D(303)= 0.174789429;
D(304)= 0.152206421; D(305)= 0.130310059; D(306)= 0.109161377; D(307)= 0.088775635;
D(308)= 0.069168091; D(309)= 0.050354004; D(310)= 0.032379150; D(311)= 0.015228271;
D(312)=-0.001068115; D(313)=-0.016510010; D(314)=-0.031082153; D(315)=-0.044784546;
D(316)=-0.057617187; D(317)=-0.069595337; D(318)=-0.080688477; D(319)=-0.090927124;
D(320)= 0.100311279; D(321)= 0.108856201; D(322)= 0.116577148; D(323)= 0.123474121;
D(324)= 0.129577637; D(325)= 0.134887695; D(326)= 0.139450073; D(327)= 0.143264771;
D(328)= 0.146362305; D(329)= 0.148773193; D(330)= 0.150497437; D(331)= 0.151596069;
D(332)= 0.152069092; D(333)= 0.151962280; D(334)= 0.151306152; D(335)= 0.150115967;
D(336)= 0.148422241; D(337)= 0.146255493; D(338)= 0.143676758; D(339)= 0.140670776;
D(340)= 0.137298584; D(341)= 0.133590698; D(342)= 0.129562378; D(343)= 0.125259399;
D(344)= 0.120697021; D(345)= 0.115921021; D(346)= 0.110946655; D(347)= 0.105819702;
D(348)= 0.100540161; D(349)= 0.095169067; D(350)= 0.089706421; D(351)= 0.084182739;
D(352)= 0.078628540; D(353)= 0.073059082; D(354)= 0.067520142; D(355)= 0.061996460;
D(356)= 0.056533813; D(357)= 0.051132202; D(358)= 0.045837402; D(359)= 0.040634155;
D(360)= 0.035552979; D(361)= 0.030609131; D(362)= 0.025817871; D(363)= 0.021179199;
D(364)= 0.016708374; D(365)= 0.012420654; D(366)= 0.008316040; D(367)= 0.004394531;
D(368)= 0.000686646; D(369)=-0.002822876; D(370)=-0.006134033; D(371)=-0.009231567;
D(372)=-0.012115479; D(373)=-0.014801025; D(374)=-0.017257690; D(375)=-0.019531250;
D(376)=-0.021575928; D(377)=-0.023422241; D(378)=-0.025085449; D(379)=-0.026535034;
D(380)=-0.027801514; D(381)=-0.028884888; D(382)=-0.029785156; D(383)=-0.030517578;
D(384)= 0.031082153; D(385)= 0.031478882; D(386)= 0.031738281; D(387)= 0.031845093;
D(388)= 0.031814575; D(389)= 0.031661987; D(390)= 0.031387329; D(391)= 0.031005859;
D(392)= 0.030532837; D(393)= 0.029937744; D(394)= 0.029281616; D(395)= 0.028533936;
D(396)= 0.027725220; D(397)= 0.026840210; D(398)= 0.025909424; D(399)= 0.024932861;
D(400)= 0.023910522; D(401)= 0.022857666; D(402)= 0.021789551; D(403)= 0.020690918;
D(404)= 0.019577026; D(405)= 0.018463135; D(406)= 0.017349243; D(407)= 0.016235352;
D(408)= 0.015121460; D(409)= 0.014022827; D(410)= 0.012939453; D(411)= 0.011886597;
D(412)= 0.010848999; D(413)= 0.009841919; D(414)= 0.008865356; D(415)= 0.007919312;
D(416)= 0.007003784; D(417)= 0.006118774; D(418)= 0.005294800; D(419)= 0.004486084;
D(420)= 0.003723145; D(421)= 0.003005981; D(422)= 0.002334595; D(423)= 0.001693726;
D(424)= 0.001098633; D(425)= 0.000549316; D(426)= 0.000030518; D(427)=-0.000442505;
D(428)=-0.000869751; D(429)=-0.001266479; D(430)=-0.001617432; D(431)=-0.001937866;
D(432)=-0.002227783; D(433)=-0.002487183; D(434)=-0.002700806; D(435)=-0.002883911;
D(436)=-0.003051758; D(437)=-0.003173828; D(438)=-0.003280640; D(439)=-0.003372192;
D(440)=-0.003417969; D(441)=-0.003463745; D(442)=-0.003479004; D(443)=-0.003479004;
D(444)=-0.003463745; D(445)=-0.003433228; D(446)=-0.003387451; D(447)=-0.003326416;
D(448)= 0.003250122; D(449)= 0.003173828; D(450)= 0.003082275; D(451)= 0.002990723;
D(452)= 0.002899170; D(453)= 0.002792358; D(454)= 0.002685547; D(455)= 0.002578735;
D(456)= 0.002456665; D(457)= 0.002349854; D(458)= 0.002243042; D(459)= 0.002120972;
D(460)= 0.002014160; D(461)= 0.001907349; D(462)= 0.001785278; D(463)= 0.001693726;
D(464)= 0.001586914; D(465)= 0.001480103; D(466)= 0.001388550; D(467)= 0.001296997;
D(468)= 0.001205444; D(469)= 0.001113892; D(470)= 0.001037598; D(471)= 0.000961304;
D(472)= 0.000885010; D(473)= 0.000808716; D(474)= 0.000747681; D(475)= 0.000686646;
D(476)= 0.000625610; D(477)= 0.000579834; D(478)= 0.000534058; D(479)= 0.000473022;
D(480)= 0.000442505; D(481)= 0.000396729; D(482)= 0.000366211; D(483)= 0.000320435;
D(484)= 0.000289917; D(485)= 0.000259399; D(486)= 0.000244141; D(487)= 0.000213623;
D(488)= 0.000198364; D(489)= 0.000167847; D(490)= 0.000152588; D(491)= 0.000137329;
D(492)= 0.000122070; D(493)= 0.000106812; D(494)= 0.000106812; D(495)= 0.000091553;
D(496)= 0.000076294; D(497)= 0.000076294; D(498)= 0.000061035; D(499)= 0.000061035;
D(500)= 0.000045776; D(501)= 0.000045776; D(502)= 0.000030518; D(503)= 0.000030518;
D(504)= 0.000030518; D(505)= 0.000030518; D(506)= 0.000015259; D(507)= 0.000015259;
D(508)= 0.000015259; D(509)= 0.000015259; D(510)= 0.000015259; D(511)= 0.000015259;


D = [0.0 D];

 

###########################################

#DeScale_factors

###########################################

function scf = DeScale_factors(scfcode)
%scf = Scale_factors(S)
% For each subband S(i, :), the maximum of the absolute value of 12
% samples S(i, 1) ... S(i, 12) is determined. The next largest value of
% the scale factor in the scale factor table [1, pp. 45] and [1, pp 70]
% is chosen.
%
% See also

% Author: Fabien A. P. Petitcolas
% Computer Laboratory
% University of Cambridge
%
% Copyright (c) 1998--2001 by Fabien A. P. Petitcolas
% $Header: /Matlab MPEG/Scale_factors.m 3 7/07/01 1:27 Fabienpe $
% $Id: Scale_factors.m,v 1.3 1998-06-24 10:20:22+01 fapp2 Exp $

% References:
% [1] Information technology -- Coding of moving pictures and associated
% audio for digital storage media at up to 1,5 Mbits/s -- Part3: audio.
% British standard. BSI, London. October 1993. Implementation of ISO/IEC
% 11172-3:1993. BSI, London. First edition 1993-08-01.
%
% Legal notice:
% This computer program is based on ISO/IEC 11172-3:1993, Information
% technology -- Coding of moving pictures and associated audio for digital
% storage media at up to about 1,5 Mbit/s -- Part 3: Audio, with the
% permission of ISO. Copies of this standards can be purchased from the
% British Standards Institution, 389 Chiswick High Road, GB-London W4 4AL,
% Telephone:+ 44 181 996 90 00, Telefax:+ 44 181 996 74 00 or from ISO,
% postal box 56, CH-1211 Geneva 20, Telephone +41 22 749 0111, Telefax
% +4122 734 1079. Copyright remains with ISO.
%-------------------------------------------------------------------------------

Table_scf = [
2.00000000000000; 1.58740105196820; 1.25992104989487; 1.00000000000000;
0.79370052598410; 0.62996052494744; 0.50000000000000; 0.39685026299205;
0.31498026247372; 0.25000000000000; 0.19842513149602; 0.15749013123686;
0.12500000000000; 0.09921256574801; 0.07874506561843; 0.06250000000000;
0.04960628287401; 0.03937253280921; 0.03125000000000; 0.02480314143700;
0.01968626640461; 0.01562500000000; 0.01240157071850; 0.00984313320230;
0.00781250000000; 0.00620078535925; 0.00492156660115; 0.00390625000000;
0.00310039267963; 0.00246078330058; 0.00195312500000; 0.00155019633981;
0.00123039165029; 0.00097656250000; 0.00077509816991; 0.00061519582514;
0.00048828125000; 0.00038754908495; 0.00030759791257; 0.00024414062500;
0.00019377454248; 0.00015379895629; 0.00012207031250; 0.00009688727124;
0.00007689947814; 0.00006103515625; 0.00004844363562; 0.00003844973907;
0.00003051757813; 0.00002422181781; 0.00001922486954; 0.00001525878906;
0.00001211090890; 0.00000961243477; 0.00000762939453; 0.00000605545445;
0.00000480621738; 0.00000381469727; 0.00000302772723; 0.00000240310869;
0.00000190734863; 0.00000151386361; 0.00000120155435; 1E-20
];

for i = 1:32,
scf(i) = Table_scf(scfcode(i));
end

###############################

#pqf

###############################

function [S X] = pqf(Input, n, C,X,fid)
%S = Analysis_subband_filter(Input, n, C)
% Returns the 32 subband samples S(i) defined in [1, pp. 67,78]
% n is the index in Input where the 32 `new'samples are located.
% C is the analysis window defined in [1, pp.68--69].
%
% See also pqf

% Author: Fabien A.P. Petitcolas
% Computer Laboratory
% University of Cambridge
% Copyright (c) 1998 by Fabien A.P. Petitcolas
% $Id: Analysis_subband_filter.m,v 1.3 1998-07-07 14:39:54+01 fapp2 Exp $

% References:
% [1] Information technology -- Coding of moving pictures and associated
% audio for digital storage media at up to 1,5 Mbits/s -- Part3: audio.
% British standard. BSI, London. October 1993. Implementation of ISO/IEC
% 11172-3:1993. BSI, London. First edition 1993-08-01.
%
% Legal notice:
% This computer program is based on ISO/IEC 11172-3:1993, Information
% technology -- Coding of moving pictures and associated audio for digital
% storage media at up to about 1,5 Mbit/s -- Part 3: Audio, with the
% permission of ISO. Copies of this standards can be purchased from the
% British Standards Institution, 389 Chiswick High Road, GB-London W4 4AL,
% Telephone:+ 44 181 996 90 00, Telefax:+ 44 181 996 74 00 or from ISO,
% postal box 56, CH-1211 Geneva 20, Telephone +41 22 749 0111, Telefax
% +4122 734 1079. Copyright remains with ISO.
%-------------------------------------------------------------------------------

nmax = length(Input);

% Check input parameters
if (n + 31 > nmax | n < 1)
error('Unexpected analysis index.');
end

% Build an input vector X of 512 elements. The most recent sample
% is at position 512 while the oldest element is at position 1.
% Padd with zeroes if the input signal does not exist.
% ...........................................................
% | 480 samples | 32 samples |
% n-480 n n+31

i = 512:-1:33;
X(i) = X(i-32);
%X(1:32) = Input(n:n + 31); error
%X(32:1) = Input(n:n + 31); error
X(32:-1:1) = Input(n:n + 31); % / 32768

% Window vector X by vector C. This produces the Z buffer.
Z = X .* C;

% Partial calculation: 64 Yi coefficients
Y = zeros(1, 64);
for i = 1 : 64,
for j = 0 : 7,
Y(i) = Y(i) + Z(i + 64 * j);
end
% fprintf(fid,'y[%d]=%0.6f\n',i,Y(i));
end

% Calculate the analysis filter bank coefficients
for i = 0 : 31,
for k = 0 : 63,
M(i + 1, k + 1) = cos((2 * i + 1) * (k - 16) * pi / 64);
end
end

% Calculate the 32 subband samples Si
%S = zeros(1, 32);
%for i = 1 : 32,
% for k = 1 : 64,
% S(i) = S(i) + M(i, k) * Y(k);
% end
% fprintf(fid,'s[%d]=%0.6f\n',i,S(i));
%end
S = M*Y';

###############################

#ipqf

###############################

function [L V]= ipqf(S, D, V)
%S = Analysis_subband_filter(Input, n, C)
% Returns the 32 subband samples S(i) defined in [1, pp. 67,78]
% n is the index in Input where the 32 `new'samples are located.
% C is the analysis window defined in [1, pp.68--69].
%
% See also pqf

% Author: Fabien A.P. Petitcolas
% Computer Laboratory
% University of Cambridge
% Copyright (c) 1998 by Fabien A.P. Petitcolas
% $Id: Analysis_subband_filter.m,v 1.3 1998-07-07 14:39:54+01 fapp2 Exp $

% References:
% [1] Information technology -- Coding of moving pictures and associated
% audio for digital storage media at up to 1,5 Mbits/s -- Part3: audio.
% British standard. BSI, London. October 1993. Implementation of ISO/IEC
% 11172-3:1993. BSI, London. First edition 1993-08-01.
%
% Legal notice:
% This computer program is based on ISO/IEC 11172-3:1993, Information
% technology -- Coding of moving pictures and associated audio for digital
% storage media at up to about 1,5 Mbit/s -- Part 3: Audio, with the
% permission of ISO. Copies of this standards can be purchased from the
% British Standards Institution, 389 Chiswick High Road, GB-London W4 4AL,
% Telephone:+ 44 181 996 90 00, Telefax:+ 44 181 996 74 00 or from ISO,
% postal box 56, CH-1211 Geneva 20, Telephone +41 22 749 0111, Telefax
% +4122 734 1079. Copyright remains with ISO.
%--------------------------------------------------------------------------
%-----
% Calculate the analysis filter bank coefficients
for i = 0 : 63,
for k = 0 : 31,
N(i + 1, k + 1) = cos((2 * k + 1) * (i + 16) * pi / 64);
end
end
n = 1024:-1:65;
V(n) = V(n-64);
V(1:64) = zeros(64,1);
for i = 1 : 64,
for k = 1 : 32,
V(i) = V(i) + N(i,k)*S(k);
end
end
%V(1:64) = N'*S;

for i = 0 : 7,
for j = 0 : 31,
U(i*64+j+1) = V(i*128+j+1);
U(i*64+32+j+1) = V(i*128+96+j+1);
end
end

W = U.*D';
L = zeros(32,1);
for j = 1 : 32,
for i = 0 : 15,
L(j,1) = L(j,1) + W(j+32*i);
end
end

posted @ 2012-04-17 11:09  杭州桓泽  阅读(499)  评论(0编辑  收藏  举报