% M02-reverb.diary % DT systems; Examples using convolution % 2007-09-11 % 'Running a system' in matlab % Because Matlab indices start at 1, we add 2 to allow us to reach back % to -1 n = -1:19; % (i.e. n(2+ i) = i, mapping time to matlab) x = zeros(1, 21); y = zeros(1, 21); % Set x[2] to a nonzero value x(2+ 2) = 5; % Run the system ("accumulator", from slide 6 of topic 2 slidepack) for i = 0:19; y(2+ i) = x(2+ i) + y(2+ i-1); end % Look at the results subplot(211) stem(n,x) subplot(212) stem(n,y) % Simple convolution calculation x=[0 3 1 2 -1]; h=[3 2 1]; subplot(321) stem(x) subplot(322) stem(h) % Convolve them y = conv(x,h) subplot(312) stem(y) % Same result if arguments in the other order y = conv(h,x) % Room reverb simulation [h,sr] = wavread('hlwy16.wav'); % Recording of clap in hallway soundsc(h,sr) [d,sr] = wavread('mpgr1_sx419.wav'); % Speech example soundsc(d,sr) % Convolve them (SLOW because many thousands of points) y=(conv(d,h)); % Listen to simulated reverberation soundsc(y,sr)