Skip to content

Instantly share code, notes, and snippets.

@jsantanders
Created November 27, 2016 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsantanders/6c330ee249ca5294725b11b551e7d625 to your computer and use it in GitHub Desktop.
Save jsantanders/6c330ee249ca5294725b11b551e7d625 to your computer and use it in GitHub Desktop.
Matlab code for digital filter example with Handel audio.
load handel.mat
y = y';
Wp = 1000/Fs; %%Frecuencia de corte normalizada
Ws = 2000/Fs; %%Frecuencia de atenuación normalizada
[n,Wn] = buttord(Wp,Ws,3,60); %%orden de butterworth
[b,a] = butter(n,Wn,'low'); %%coeficientes de butterworth
yh = filter(b, a, y); %%Filtro de la señal
L=length(y);
NFFT = 2^nextpow2(L); % Siguiente potencia de 2 del vector y
f = Fs/2*linspace(0,1,NFFT/2+1);
figure(1)
yf=fft(y,NFFT)/L;
plot(f,2*abs(yf(1:NFFT/2+1)))
title('Espectro de la señal')
xlabel('Frecuencia [Hz]')
grid on
figure(2)
yf2=fft(yh,NFFT)/L;
plot(f,2*abs(yf2(1:NFFT/2+1)))
title('Espectro de la señal filtrada')
xlabel('Frecuencia [Hz]')
grid on
figure(3)
[H,W] = freqz(b,a,1000);
plot(Fs.*W./pi,abs(H))
title('Respuesta en frecuencia del filtro')
xlabel('Frecuencia [Hz]')
grid on
sound(yh)
sound (y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment