// Prueba de la función fftfilter()

clear
close(winsid())
mode(0);

// Cargar la función

exec fftfilter.sci;

// Signal duration
T = 0.5;
// Sample rate
Fs = 44100;
// FFT window length
N = 4096;
// Centre frequency
f = (Fs/N)*105;
// Time vector
t = 0:1/Fs:T;

// Signal with two partials, one within the
// pass band and another outside it
x = sin(2*%pi*f*t) + sin(2*%pi*1.2*f*t);

// Filtering window: a very narrow window 
w = [zeros(1, floor((N/Fs)*f) - 1), ..
     1, 1, 1, ..
     zeros(1, N/2 - floor((N/Fs)*f) - 2)];

tic
y = fftfilter(x,w,N);
toc

scf(1);
clf(1);
subplot(3,1,1)
plot(t,x)
title("Señal original")
xlabel("t  [s]")
ylabel("x")
gca().data_bounds = [0 -max(x); 0.02 max(x)];
subplot(3,1,2)
  plot(t,y)
  title("Señal filtrada")
  xlabel("t  [s]")
  ylabel("y")
  gca().data_bounds = [0 -max(x); 0.02 max(x)];
subplot(3,1,2)
  plot(t,y)
  title("Señal filtrada")
  xlabel("t  [s]")
  ylabel("y")
  gca().data_bounds = [0 -max(x); 0.02 max(x)];
subplot(3,1,3)
  plot(t, x - y)
  title("Señal original - señal filtrada")
  xlabel("t  [s]")
  ylabel("x - y")
  gca().data_bounds = [0 -max(x); 0.02 max(x)];



scf(2);
clf(2);
plot(t,y-x)


