% Jonathon Panek
% EE 416
% Project 2
% Due 10/26/01
% =====================================================
% Read in the wav file
    a=wavread('sample');
% Transpose the vector
    b=a';
% Take the first 128 data points
    c=b(1:128);
% Take the fourier transform
    d=fft(c);
% Zero pad the sample for a total of 512 points
    e=[c, zeros(1,384)];  
% Take the fourier transform of the zero padded sample
    f=fft(e);
% Magnitude (dB) & phase of the non-zero-padded sample
    m1=20*log10(abs(d));
    p1=angle(d);
% Magnitude (dB) & phase of the zero-padded sample
    m2=20*log10(abs(f));
    p2=angle(f);
% Create the frequency vectors for the plots of d & f
    f1=(-(length(d)-1)./2:(length(d)-1)./2)*128/length(d);
    f2=(-(length(f)-1)./2:(length(f)-1)./2)*512/length(f);
% Plots of sample with and without zero-padding
    figure(1);
    subplot(2,2,1);
    plot(f1,m1);
    xlabel('Samples');
    ylabel('Magnitude (dB)');
    title('Magnitude of Non-Zero-Padded Sample');
    subplot(2,2,2);
    plot(f1,p1);
    xlabel('Samples');
    ylabel('Phase (degrees)');
    title('Phase of Non-Zero-Padded Sample');
    subplot(2,2,3);
    plot(f2,m2);
    xlabel('Samples');
    ylabel('Magnitude (dB)');
    title('Magnitude of Zero-Padded Sample');
    subplot(2,2,4);
    plot(f2,p2);
    xlabel('Samples');
    ylabel('Phase (degrees)');
    title('Phase of Zero-Padded Sample');
    
% The resolution of the zero padded sample is higher because 
% there are more points to take the transform of.

% A 128th order FIR high-pass digital filter 
    figure(2);  
    k = fir1(128,.5,'high');
    freqz(k,1,500);
    
% The frequencies of the sample that are below .5*sampling frequency
% will be cut out up to about -60 dB
    
% A 200th order FIR sampling-based digital high-pass filter
    figure(3);
    f=[0 0.5 0.5 1];
    m=[0 0 1 1];
    k = fir2(200,f,m);
    freqz(k,1,500);
    
% The frequencies of the sample that are below .5*sampling frequency
% will be cut out up to about -60 dB

% A 10th order high-pass digital butterworth filter
    figure(4);
    [b,a] = butter(20,.7, 'high');
    freqz(b,a,128,1000);
    
% The butterworth will cut off frequencies less than 350 Hz.
% The rolloff of this filter is much slower than the
% FIR type filters.

% ============================================================
% MP3 encoders zero pad a sound sample to increase resolution.
% This improves the audio quality of the sample.
    
    
    

    
    