%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This m-file shows how to use D-T convolution to explore the effect of
%% and resonant circuit on an audio signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Create and plot Frequency Response of a system
f=0:20e3;
w=2*pi*f;
a=200;
w_o=2*pi*1000;
H=(w_o^2)./( (a+j*w).^2 + (w_o^2));
plot(f,abs(H))
[x,Fs]=wavread('guitar1.wav'); % read in wave file of guitar recording
del_t=1/Fs; % Fs is sampling rate read in by wavread.m so invert it to get time spacing
t=(0:500)*del_t; %% create 501 point time sample vector
%% compute impulse response of this circuit at the 501 time points
%%%% Use a FT table to find the inverse FT of this H(w)
h=w_o*exp(-a*t).*sin(w_o*t);
% plot(t,h) %% note that h(t) decays to negligible values by the end of the 501 time points
% xlabel('time (s)')
% ylabel('RC Impulse Response (volts)')
%% use del_t*h(nTs) to make D-T conv approximate C-T conv
%% See Eq. (3.64) in Sect 3-5 of book
y=conv(x,del_t*h); %% this D-T convolution approximates the C-T convolution that
%% the RC circuit does
disp('Hit any key to start first playback')
pause
sound(x,Fs); %%% Listen to the original signal (the input to the RC circuit)
disp('When playback stops... Hit any key to start playback of output')
pause %%% wait until first playback is over.. then user must hit a key
sound(y,Fs); %%% Listen to the signal at the output of the RC circuit...
%% notice that it has less treble content (i.e. less high frequency)