function out=project5coder(x,f)
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
Fs = 2^13;                            % Fs=sampling rate
b=4; 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
x=0.3*x/max(abs(x));                  % normalize signal to max amplitude = 0.3
%sound(x,Fs)                           % Matlab's sound command
out=[];
for k=1:nw-1                          % loop over l ength 2n windows
  x0=x(1+(k-1)*n:2*n+(k-1)*n)';
  y0=M*x0;
  y1(:,k)=round(y0/q);                     % transform components quantized
end
out = y1;
numel(y1)*b
