% Demonstration of music convolved with various impulse responses.
% This program must be run on the Sun computers to access the music file.
%
% ELEC 320, Rich Kozick

% Filter music with an impulse response (1st order)

fs = 8192;	% Sample rate
T = 1/fs;

fc = 300;	% Desired cutoff freq, in Hz 
wc = 2*pi*fc;

% Make impulse response length equal to 5 time constants

t = 0:T:(5/wc);
g = wc*T*exp(-t*wc);

figure(1)
plot(t, g);
title('Impulse response g(t)');
xlabel('Time (sec.)');
ylabel('Amplitude');

f = auread('/home/pleiades/COURSES/ee328/slove.au');

fprintf('This is the original music . . . ');
sound(f)
fprintf('\nComputing -- please wait . . . ');
y = conv(f, g);
fprintf('\nThis is after convolution with g(t) . . . ');
sound(y)

fprintf('\nComputing -- this takes a while . . . ');
h = [g, zeros(size(0:T:.4)), .5*g];

figure(2)
th = (1:length(h))*T;
plot(th, h)
title('Impulse response h(t)');
xlabel('Time (sec.)');
ylabel('Amplitude');

z = conv(f, h);
fprintf('\nThis is after convolution with h(t) . . . ');
sound(z);
fprintf('\n');

fprintf('To repeat the sounds:\n')
fprintf('sound(f) is the original\n')
fprintf('sound(y) is convolved with g(t)\n')
fprintf('sound(z) is convolved with h(t)\n')
