% file: homework_05.m
%
% this function computes the SNR (signal to noise ratio) of a raw data file
%
% arguments:
%  sample_freq		frequency of the input data in kHz
%  emphasis_val		parameter used in pre-emphasis
%  window_duration	duration of the window in secs
%  window_center	center time for the window in secs
%  window_type		string containing either: hamming, rectangular
%  lpc_order		the linear prediction order
%  in_file		binary input file
%
% return value: 
%
% output: 
%

function hw5(sample_freq,emphasis_val,window_duration,window_center,window_type,lpc_order,in_file)

% open the raw data file
%
fp = fopen(in_file,'r');

% determine the number of samples per window
%
num_samp_window = floor(window_duration*sample_freq);


% read in the raw data (16-bit int)
%
[data,count] = fread(fp,inf,'int16');

% determine the indices of the data in the window
%
window_center_index = window_center * sample_freq;
window_left_index = window_center_index - floor(num_samp_window/2);

data = data(window_left_index+1:window_left_index+num_samp_window)

data = debias(data,num_samp_window);

% pre-emphasize the data
%
pe_data = pre_emphasis(data,emphasis_val);

% apply window to the data
%
% create window function to window the raw data
%
upper(window_type);
if (strcmp(window_type,'HAMMING'))
   windowed_data = hamming_window(num_samp_window,pe_data);
else
   windowed_data = pe_data;
end

[lpc_data,gain] = calculate_lp_coeffs(windowed_data,lpc_order);
lpc_spectrum = lpc_spect(lpc_data, lpc_order, num_samp_window, gain);
plot(20*log10(abs(lpc_spectrum)));

hold on;
signal_spectrum=dft(windowed_data,num_samp_window);
plot(20*log10(abs(signal_spectrum)));

% close the raw data file
%
fclose(fp);




