% Moving average filter
j=sqrt(-1);
 
Nfft = 256;
range=(1:Nfft);
Fs=32000;           % sampling rate
N=2^18;           % length of a filter
d=N/2;              % delay
wscale = pi/8000;  % max freq. to plot
w=wscale/Nfft*(0:Nfft-1);
 
E=exp(-j*w*d);
%h=1/N*ones(size(1:N));
%H=freqz(h,1,Nfft);
H(1) = 1;
range2=2:Nfft;
H(range2) = exp(-j*w(range2)/2*(N-1)) .* sin(w(range2)*N/2) / N ./ sin(w(range2)/2);
mH=20*log10(abs(H));
 
G=E-H;
mG=20*log10(abs(G));
trmH = mH;
idx = find(mH<-70);
sidx = size(idx);
if max(sidx) > 0, trmH(idx) = -70*ones(sidx(1),sidx(2)); end;
plot(Fs/2*w(range)/pi, trmH(range), Fs/2*w(range)/pi, mG(range));
