%
%     MATLAB PROJECT 2
%
% Name - Kris Tuthill
% PN# - 26505936
% 
% Date - 10/26/01
%
% Course - EE416
% 
%


%
% 1.

  x= wavread('sample.wav');     % read in sample wav file
  
  
  X= x(1:128);                  % sample first 128 data points as a column vector
  X1=X';                        % transpose into a row vector
  
  figure(1);
  plot(X1);                     % plot of sampled signal
  title('Signal 1');
  xlabel('Time');
  ylabel('Amplitude');
  
  
  %
  % 2.
  
   Y= [X1, zeros(1,384)];       % pad sampled signal with zeros, sum of data points is a power of 2

   figure(2);
   plot(Y);                     % plot padded signal
   title('Signal 2');
   xlabel('Time');
   ylabel('Amplitude');
   
   
   %
   % 3.
   
   inc1= 2*pi/128;              % step size for incrementer 1 
   inc2= 2*pi/512;              % step size for incrementer 2
   
   w1= -pi:inc1:pi;             % increment from -pi to pi, for sample signal
   w= w1(1:128);                % chop to 128 data points
   v1= -pi:inc2:pi;             % increment from -pi to pi, for padded signal
   v= v1(1:512);                % chop to 512 data points
   m= fftshift(fft(X1));        % take FFT of sample signal and shift it to center 0 frequency
   n= fftshift(fft(Y));         % take FFT of padded signal and shift it to center 0 frequency
   
   phase1= unwrap(angle(m));    % unwrap phase of sample signal
   phase2= unwrap(angle(n));    % unwrap phase of padded signal
  
   figure(3);
   subplot(2,2,1);
   plot(w,abs(m))               % plot, magnitude of sample signal
   title('Magnitude signal 1');
   subplot(2,2,2);
   plot(w,phase1)               % plot, phase of sample signal         
   title('Phase signal 1');
   subplot(2,2,3);
   plot(v,abs(n))               % plot, magnitude of padded signal
   title('Magnitude signal 2');
   subplot(2,2,4);
   plot(v,phase2)               % plot, phase of padded signal
   title('Phase signal 2');
   
   
   %
   % 4.
   %
   %  Zero-padding the sample siganl decreased the spectral resolution and increased the spectral density 
   %  of the resulting signal. 
   %
   %
   
   
   
   
   %
   % 5.
   
   W= [0.33 0.66];              % cutoff frequencies for bandpass filter
   
   B1= fir1(10, W);             % FIR1 filter, 10th order
   B2= fir2(12, W);             % FIR2 filter, 12th order
   B3= remez(20, W);            % Parks-McClellan filter, 20th order
   B4= cheby1(24, W);           % Chebychev1 filter, 24th order
   
   y1= filter(B1,1,X1);         % implement FIR1 filter, ripple 1dB
   y2= filter(B2,1,X1);         % implement FIR2 filter, ripple 1dB
   y3= filter(B3,1,X1);         % implement Parks-McClellan filter, ripple 1dB
   y4= filter(B4,1,X1);         % implement Chebychev1 filter, ripple 1dB
   
   
   figure(4);
   subplot(2,2,1);
   plot(y1)                      % plot, FIR1 bandpass filter
   title('FIR1, fir bandpass');
   subplot(2,2,2);
   plot(y2)                      % plot, FIR2 filter
   title('FIR2, fir bandpass');
   subplot(2,2,3);
   plot(y3)                      % plot, Parks-McClellan filter    
   title('REMEZ, Parks-McClellan bandpass ');
   subplot(2,2,4);
   plot(y4)                      % plot, Chebychev filter
   title('CHEBY1, Chebychev bandpass');
     
   
   %
   % 6.
   
   % MP3 is more properly known as MPEG-1 Layer 3 or MPEG-2 Layer 3.  It
   % is a standard for the transmission and decoding of compressed audio.
   % The MP3 format is fairly simple; it contains the description of
   % a number of different types of sound data (especially spectral
   % frames) represented in a concise format.  To decode this, you
   % create the sound that's described in the format.  To encode an mp3, the sound is 
   % first transformed into the frequency domain, then a hearing model is used to 
   % evaluate what parts of the sound are "most important".  Bits are then allocated 
   %  to the various parts in decreasing order of importance, with the most important 
   % parts of the sound receiving the most bits.  Next, all of the bits are compressed 
   % with a noiseless coding scheme e.g.Huffman coding.  Finally the result is packed 
   % into the standardized format


   
   
   
   
   
   
   
   
   
   
   
   
   
   
