% calculates the energy of a signal
function p_hat = keep_1std(audiofile)
s = wavread(audiofile);
% size of original file
ln = length(s(:,1));
P = dct(s(:,1));
en = zeros(ln,1);
for i=1:ln
    en(i) = (1/(2*pi)).*(abs(P(i))^2);
end

% find the mean of the energy spectrum
mean_en = mean(en);
% find the standard deviation of the energy spectrum
std_en_1 = std(en);

% lower bound of 1 standard deviation from the mean
low_limit_1 = mean_en - std_en_1;
% upper bound of 1 standard deviation from the mean
upper_limit_1 = mean_en + std_en_1;


j = find(P < low_limit_1);
P(j) = 0;
j_length = length(j);
k = find(P > upper_limit_1);
P(k) = 0;
k_length = length(k);

% size of compressed parts
compressed_total = j_length + k_length;
% size of audio file after compression
size_after_compression = ln - compressed_total;
% percent comrpessed
percent_of_compression = compressed_total/ln;

p_hat = idct(P);
sound(p_hat,22050)





