% Moving average filter

range=(1:256);
Nfft = 256;
Fs=50000;
N=250000;
d=N/2;
wscale = pi/10000;
w=wscale/Nfft*(0:Nfft-1);

E=exp(-j*w*d);
%h=1/N*ones(size(1:N));
%H=freqz(h,1,Nfft);
H = exp(-j*w/2*(N-1)) .* sin(w*N/2) / N ./ sin(w/2);
H(1) = 1;
mH=20*log10(abs(H));

G=E-H;
mG=20*log10(abs(G));
trmH = mH;
idx = find(mH<-70);
trmH(idx) = -70*ones(size(idx));
plot(Fs/2*w(range)/pi, trmH(range), Fs/2*w(range)/pi, mG(range));
