function Error=SimpleCodecOutput(len,OutputBits,Windowing) n=2^5; % length of window nw=floor(len/n); % number of length n windows in x Fs=2^(13); % Fs=sampling rate b=2; L=0.3; % b = quantization bits, [-L,L] amplitude range q=2*L/(2^b-1); % q used for b bits on interval [-L, L] %%% The following for loop creates the MDCT matrix %%% for i=1:n % form the MDCT matrix for j=1:2*n M(i,j)= cos((i-1+1/2)*(j-1+1/2+n/2)*pi/n); end end M=sqrt(2/n)*M; N=M'; % inverse MDCT %%% The following if block creates a windowing vector or an array of ones depending on the choice %%% if Windowing == 1 h=1:1:2*n; h=sqrt(2).*sin((h+.5).*(pi/(2*n))); % Windowing function else h=ones(1,2*n); end h=h.'; %x=x.*h; out=[]; for k=1:nw-1 % loop over l ength 2n windows y1=OutputBits(:,k) y2=y1*q; % transform components dequantized w(:,k)=(N*y2).*h; % invert the MDCT and undo windowing if(k>1) w2=w(n+1:2*n,k-1);w3=w(1:n,k); out=[out;(w2+w3)/2]; % collect the reconstructed signal end % (of length 2n less than length of x) end %%% The following if statement plays the sound depending on the choice in the arguments %%% sound(out,Fs) % play the reconstructed tone %