Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 9-1 (15 points) Write a Matlab function to implement the overlap-save me

ID: 1923411 • Letter: P

Question

Problem 9-1 (15 points)
Write a Matlab function to implement the overlap-save method of convolution. Use your function to demonstrate filtering of the noise-corrupted signal x[n] using a length-3 moving average flter with impulse response h[n]. Both x[n] and h[n] can be generated using the matlab function below.

function [x,h] = noisysig();


n = 0:255;
xs = 0.1*n.*exp(-0.03*n);
%subplot(3,1,1)
%plot(n,x);axis([0 255 0 1.3]);
%xlabel('n');ylabel('Amplitude');
%title('Origianl Signal');

z = [zeros(1,50) ones(1,156) zeros(1,50)];
y = 4*rand(1,256)-1;
YF = z.*fft(y);
yinv = ifft(YF);
x = xs+yinv; % Noisy signal
%subplot(3,1,2)
%plot(n,s);axis([0 255 -2 4]);
%xlabel('n');ylabel('Amplitude');
%title('Noise corrupted signal');
M = 3;
h = ones(M,1)/M; % 3-point MA filter impulse response

Explanation / Answer

function [y] = ovrlpsav(x,h,N) % Overlap-Save method of block convolution % ---------------------------------------- % [y] = ovrlpsav(x,h,N) % y = output sequence % x = input sequence % h = impulse response % N = block length % Lenx = length(x); M = length(h); M1 = M-1; L = N-M1; h = [h zeros(1,N-M)]; % x = [zeros(1,M1), x, zeros(1,N-1)]; % preappend (M-1) zeros K = floor((Lenx+M1-1)/(L)); % # of blocks Y = zeros(K+1,N); % convolution with succesive blocks for k=0:K xk = x(k*L+1:k*L+N); Y(k+1,:) = cconv(xk,h); end Y = Y(:,M:N)'; % discard the first (M-1) samples y = (Y(:))'; % assemble outpu function op = cconv(x,y) %CCONV N-point circular convolution % % op = CCONV(x,y) performs the N-point circular convolution % of vectors x and y. 'op' is returned as a row vector. x and y % must be vectors of equal lengths. % % See also CONV % % Peter Mash % pete@lightblueoptics.com % 17-Nov-2006 Nx = length(x); Ny = length(y); % catch error - different lengths if(Nx~=Ny) error('Vectors must be the same length in this version'); end % catch error - x or y is a matrix not a vector [N M] = size(x); if((N