%Program 11.1 Audio codec %input: number of quantization bits; 1 is there is windowing, 0 if there is %no windowing %output: vector out of output signal %Example usage: out=simplecodec(cos((1:2^(12))*2*pi*256/2^(13))); % example signal is 1/2 sec. pure tone of frequency f = 256 function audioComp5(qBits,windowing) [x,Fs] = audioread('Tristram.mp3'); len=length(x); n=32; % length of window nw=floor(len/n); % number of length n windows in x x=x(1:n*nw); % cut x to integer number of n windows xshort = x(n+1: end-n); % cut for the original signal xshort = 0.3*xshort/max(abs(xshort)); % normalize signal to max amplitude = 0.3 % Fs=2^(13); % Fs=sampling rate b=qBits; 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] 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 %if there is windowing, then h(j) will be created, if not, h will stay as 1 h=1; if (windowing == 1) for j = 1:2*n % creates h(j), addition for windowing function h(j) = sqrt(2)*sin((j-.5)*pi/(2*n)); end h = h'; end x=0.3*x/max(abs(x)); % normalize signal to max amplitude = 0.3 out=[]; for k=1:nw-1 % loop over length 2n windows x0=(x(1+(k-1)*n:2*n+(k-1)*n)').*h; y0=M*x0; y1=round(y0/q); % transform components quantized % Storage/transmission of file occurs here y2=y1*q; % transform components dequantized w(:,k)=(N*y2).*h; % invert the MDCT 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 RMSE = sqrt(mean((xshort(:) - out(:)).^2)) %audiowrite('TristramCompressed.wav', out, Fs);
Not enough input arguments. Error in audioComp5 (line 16) b=qBits; L=0.3; % b = quantization bits, [-L,L] amplitude range