%---------------------------------------------------------------% %------ 2) Plotting the mag and phase response of the ---------% %------ Karplus-Strong Filter with a 300Hz signal ---------% %---------------------------------------------------------------% fs = 44100; fo = 300; L = fs/fo-0.5; delta = L-floor(L); % gives us the fractional delay. =0.5 L = floor(L); % gives us the integer delay. =146 a = (1-delta)/(1+delta); L_delay = zeros(1,L-2); % allows us to use a sample delay of L R = 0.999; % R is the gain, must be less than 1 B = [(a/2), (a/2+1/2), 1/2, L_delay]; A = [1, a, L_delay, (-a/2*R^L), -(a/2*R^L+1/2*R^L), (-0.5*R^L)]; [H, W] = freqz(B, A, 1024); % B is the num and A is the den of H(z) W = (W*fs)/(2*pi); figure(); subplot(2,1,1); plot(W, abs(H)); title('Magnitude Response of Karplus-Strong (300Hz)'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(2,1,2); plot(W, angle(H)); title('Phase Response of Karplus-Strong (300Hz)'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); %---------------------------------------------------------------% %---- 4) Filtering and plotting an impulse through the KS -----% %---------------------------------------------------------------% impulse = [1, zeros(1, 3*fs)]; % 1 is the impulse followed by many KS_impulse = ksfilter(fo,fs,impulse); % zeros so we can hear the effects sound(KS_impulse,fs); % of the KS filter ts = 1/fs; t = 0:ts:3; figure(); plot(t, KS_impulse); axis([0 3 -1.1 1.1]); title('An impulse modeled by the KS filter'); xlabel('Time (s)'); ylabel('Amplitude'); wavwrite(KS_impulse,fs,'Lab6-Impulse_Response'); %---------------------------------------------------------------% %---- 5) Filtering and plotting noise through the KS ----------% %---------------------------------------------------------------% noise = 2*rand(1,(0.01*fs)+1)-1; % The noise burst lasts noise = [noise, zeros(1,(3*fs)-(0.01*fs))]; % for a very short time KS_noise = ksfilter(fo,fs,noise); % Again followed by zeros sound(KS_noise,fs); figure(); plot(t, KS_noise); axis([0 3 -1.1 1.1]); title('A noise burst modeled by the KS filter'); xlabel('Time (s)'); ylabel('Amplitude'); wavwrite(KS_impulse,fs,'Lab6-Noise_Burst');