%PART 1 clear rng(0); %set seed for random number generator for conistent results N = 256; T = (0:N-1)/N; %make and plot trial signal f= .5*cos(20 * pi *T) + (1/3)*cos(48*pi*T) + 0.5*randn(1, N); forigin = .5*cos(20 * pi *T) + (1/3)*cos(48*pi*T); plot(T,forigin, T,f) figure plot(fftshift(abs(fft(forigin)))); %plot centered spectrum of the pure signal figure plot(fftshift(abs(fft(f)))); %plot centered spectrum of the noisy signal figure gtent = zeros(1,N); %create the time domain filtered signal for n = 1:N for j=(-N/2 +1):N/2 gtent(n) = gtent(n) + wtent(j)* f(mymod1(n+j,N)); end end plot(fftshift(abs(fft(gtent)))); %plot centered spectrum of the filtered signal figure plot(T,forigin, T, gtent) %compare original no-noisy signal with filtered one function y = wtent(x) if (abs(x) <1 ) y = 1/2; elseif (abs(x) < 2) y = 1/4; else y = 0; end end %mymod1 is a utility to reduce indices for circular %addition using matlab indexing of 1 to N function y = mymod1( a,m ) z = mod(a,m); if z == 0 y = m; else y = z; end end