%---------------------------------------------------------------% %------ 2) Plotting a few seconds of an audio signal ----------% %---------------------------------------------------------------% [y,fs,NBITS] = wavread('wavefile.wav',[1000,751000]); y = y(:,1); %converting waveform to mono sound(y,fs); magPlot(y,fs,'Frequency Spectrum'); wavwrite(y,fs,'NatePaternoster-Lab7-2.wav'); %---------------------------------------------------------------% %------ 3) Plotting a few seconds of an audio signal ----------% %---------------------------------------------------------------% % a. Using summation of sums of input x and impulse response h x = [0, 0, 0, 1]; % x and h are vectors h = [1, 1, 1, 1]; y = convolve(x,h); z = conv(x,h); % b. Using convolution theorem and FFT x1 = [0, 0, 0, 1]; % x1 and h1 are vectors h1 = [1, 1, 1, 1]; y1 = convolve2(x1,h1); z1 = conv(x1,h1); % c. Comparing the two methods of convolution [input,fs] = wavread('snare1.wav'); [impulse,fs2] = wavread('room_impulse.wav'); input = input'; impulse = impulse'; tic; output_a = convolve(input,impulse); toc; tic; output_b = convolve2(input,impulse); toc; soundsc(output_b,fs); output_b = 0.04*output_b; wavwrite(output_b,fs,'NatePaternoster-Lab7-3');