%�@sample program gfilt.m
dt = 1/1000; % assumed sampling frequency                      
n=1024;
t=(0:n-1)*dt;   % to make x-axis data for plot                                       
y1=sin(2*pi*t*5); y2=sin(2*pi*t*250); y3=sin(2*pi*t*450);
y=y1+y2+y3;ffty=fft(y);
F1=300;F2=100;
index1= round(F1*(dt*n));index2= round(n-F1*(dt*n));
Lowpass=ones(size(ffty)); 
Lowpass(index1+1:index2-1)=zeros(size(Lowpass(index1+1:index2-1)));
index1= round(F2*(dt*n));index2= round(n-F2*(dt*n));
Highpass=zeros(size(ffty)); 
Highpass(index1:index2)=ones(size(Highpass(index1:index2)));
yout = real(ifft(Lowpass.* Highpass.*ffty));
ff=(0:length(ffty)-1)/dt;
hlflen=length(ffty)/2;
subplot(2,2,1);plot(ff(1:hlflen),abs(ffty(1:hlflen)),'r');xlabel('Frequency (Hz)'), ylabel('Magnitude');
title('Original Signal in freq domain');
%% Now apply fft filter in freq domain
subplot(2,2,3)
LHffty=(Lowpass.* Highpass).*ffty ;
plot(ff(1:hlflen),abs(LHffty(1:hlflen)),'r');xlabel('Frequency (Hz)'), ylabel('Magnitude');
title('Designed filter')
subplot(2,2,2)
plot(t,y,'r');xlabel('Time (seconds)');ylabel('Time waveform');title('Original Signal');
subplot(2,2,4)
plot(t, real(ifft(Lowpass.* Highpass.*ffty)),'r'); xlabel('Time (seconds)');ylabel('Time waveform');
title('Filterd Signal by using fft');
