function [freqrange powspec] =  PowSpec(filename, size)
    % asks for a file and some size choices, plots power spectrum.
    % size is how many data points to fft (power of two), and is twice
    % the resolution of the pow spec.
    % sound .wav files are 2 sec. long, so 44K for most, 88K for guitar.
    % reasonable data sizes:  2048,  4096,  8192,  16384, 32768, (guitar only) 65536;

        disp ('WavReading Sound File');
        disp(filename);
[sound, freq] = wavread(filename, 'double'); 
  %get sound as double vector, freq. of recording   
 
disp('Hit any key to listen:');
pause;
wavplay(sound, freq);
%strictly for Windows!

disp('Plotting Sound:');
plot(1:size, sound(1:size), '-b');
title('Sound');
figure;

disp('Power Spectrum...');
freqrange = linspace(0,freq/2,(size/2)+1);
% Nyquist says: sense waves <= 1/2 freq of samples
soundfft = fft(sound, size);
powspec = soundfft .* conj(soundfft);

powspec = powspec(1:(size/2)+1);
plot(freqrange, powspec, '-r');
title ('PS, freqs 0 at origin to sampfreq/2');

end

