如何使用巴特沃斯低通滤波器过滤音频?
How can I filter an audio using butterworth lowpass filter?
我正在尝试过滤音频信号,但我在 scilab 中找不到 IIR 滤波器函数,我可以将它与我的代码的其他函数结合起来,给出一个分子和分母,我称之为 b2 和 a2(2 ° 节)。
我试过使用函数 zpbutt,但我没有用 me.Also,我试过函数 analpf()
//Code to filter a audio called sirene.wav
clc;
clear;
close;
//Load the audio
wavread("C:\Users\kaline\Desktop\Disciplinas19.1\PDS° etapa\Trabalho final\sirene.wav","size")
[y,fs,bits]=wavread("C:\Users\kaline\Desktop\Disciplinas19.1\PDS° etapa\Trabalho final\sirene.wav");fs,bits
y=loadwave("C:\Users\kaline\Desktop\Disciplinas19.1\PDS° etapa\Trabalho final\sirene.wav");
//playsnd(y)
//Cpturing information
Ts = 1/fs; // sampling time
t = 0:Ts:1-Ts; //Interval of the sampling
fa=[0:1:length(y)-1]; //fa scroll the signal samppling
f=fa.*fs/(length(y)-1); //Frequency vectors in Hertz
X=abs(fft(y)); //frequency spectrum of the audio signal
// Show plots
subplot(2,1,1);
plot(fa,abs(y));
title('Sinal de Voz');
subplot(2,1,2);
plot(f(1:round(length(y)/2)),X(1:round(length(y)/2)));
title('Espectro do sinal');
//1° section:Notch filter
//hz=iir(n,ftype,fdesign,frq,delta)
//[p,z,g]=iir(n,ftype,fdesign,frq,delta)
r = 0.9926;
fc = 200;
wc = (2*%pi*fc)/fs;
a = [1 -2*r*cos(wc) r^2];
b = [1 -2*cos(wc) 1];
[xm,fr]=frmag(b,a,512);
Y=fft(y);
z=filter(b,a,y);
w=fft(z);
//Coeficientes do primeiro filtro notch
disp('Coeficientes do primeiro filtro notch');
disp(b);
disp(a);
//Apresentando os plots
figure;
title('filtro Notch');
subplot(3,1,1)
plot(fr*fs,abs(xm))
subplot(3,1,2)
plot(f,abs(Y)),
title('Resposta em frequência do sinal original');
subplot(3,1,3)
plot(f,abs(w),'r')
title('Resposta em frequência do sinal filtrado');
//2° section: Butt filter
n = 10;
wc = 0.5;
//[b2, a2] = zpbutt(n,wc); // Parâmetros de entrada
[b2,a2]= iir(n, "lp", "butt",[wc],[]);
[H1, W1]= frmag(b2,a2,512); //frequency response
s = filter(b2,a2,z); // Filtering the signal
S = abs(fft(s)); // frequency response of filtered signal
//[I,T] = impz(b2, a2); //impulse response of filter IIR
//Coeficientes do filtro de butterworth
disp('Coeficientes do filtro de butterworth');
disp(b2);
disp(a2);
实际上我正在尝试使用给我错误的函数 iir:
过滤器:输入参数 #1 的类型错误:应为实数矩阵或多项式。
尝试以下操作:
//2° section: Butt filter
n = 10;
wc = 0.5;
//[b2, a2] = zpbutt(n,wc); // Parâmetros de entrada
[hz]= iir(n, "lp", "butt",[wc],[])
disp(hz)
a2 = hz.num
b2 = hz.den
[H1, W1]= frmag(a2,b2,512); //frequency response
s = filter(a2,b2,z); // Filtering the signal
S = abs(fft(s)); // frequency response of filtered signal
//[I,T] = impz(b2, a2); //impulse response of filter IIR
//Coeficientes do filtro de butterworth
disp('Coeficientes do filtro de butterworth');
disp(b2);
disp(a2);
这是你想要的吗?
我正在尝试过滤音频信号,但我在 scilab 中找不到 IIR 滤波器函数,我可以将它与我的代码的其他函数结合起来,给出一个分子和分母,我称之为 b2 和 a2(2 ° 节)。
我试过使用函数 zpbutt,但我没有用 me.Also,我试过函数 analpf()
//Code to filter a audio called sirene.wav
clc;
clear;
close;
//Load the audio
wavread("C:\Users\kaline\Desktop\Disciplinas19.1\PDS° etapa\Trabalho final\sirene.wav","size")
[y,fs,bits]=wavread("C:\Users\kaline\Desktop\Disciplinas19.1\PDS° etapa\Trabalho final\sirene.wav");fs,bits
y=loadwave("C:\Users\kaline\Desktop\Disciplinas19.1\PDS° etapa\Trabalho final\sirene.wav");
//playsnd(y)
//Cpturing information
Ts = 1/fs; // sampling time
t = 0:Ts:1-Ts; //Interval of the sampling
fa=[0:1:length(y)-1]; //fa scroll the signal samppling
f=fa.*fs/(length(y)-1); //Frequency vectors in Hertz
X=abs(fft(y)); //frequency spectrum of the audio signal
// Show plots
subplot(2,1,1);
plot(fa,abs(y));
title('Sinal de Voz');
subplot(2,1,2);
plot(f(1:round(length(y)/2)),X(1:round(length(y)/2)));
title('Espectro do sinal');
//1° section:Notch filter
//hz=iir(n,ftype,fdesign,frq,delta)
//[p,z,g]=iir(n,ftype,fdesign,frq,delta)
r = 0.9926;
fc = 200;
wc = (2*%pi*fc)/fs;
a = [1 -2*r*cos(wc) r^2];
b = [1 -2*cos(wc) 1];
[xm,fr]=frmag(b,a,512);
Y=fft(y);
z=filter(b,a,y);
w=fft(z);
//Coeficientes do primeiro filtro notch
disp('Coeficientes do primeiro filtro notch');
disp(b);
disp(a);
//Apresentando os plots
figure;
title('filtro Notch');
subplot(3,1,1)
plot(fr*fs,abs(xm))
subplot(3,1,2)
plot(f,abs(Y)),
title('Resposta em frequência do sinal original');
subplot(3,1,3)
plot(f,abs(w),'r')
title('Resposta em frequência do sinal filtrado');
//2° section: Butt filter
n = 10;
wc = 0.5;
//[b2, a2] = zpbutt(n,wc); // Parâmetros de entrada
[b2,a2]= iir(n, "lp", "butt",[wc],[]);
[H1, W1]= frmag(b2,a2,512); //frequency response
s = filter(b2,a2,z); // Filtering the signal
S = abs(fft(s)); // frequency response of filtered signal
//[I,T] = impz(b2, a2); //impulse response of filter IIR
//Coeficientes do filtro de butterworth
disp('Coeficientes do filtro de butterworth');
disp(b2);
disp(a2);
实际上我正在尝试使用给我错误的函数 iir:
过滤器:输入参数 #1 的类型错误:应为实数矩阵或多项式。
尝试以下操作:
//2° section: Butt filter
n = 10;
wc = 0.5;
//[b2, a2] = zpbutt(n,wc); // Parâmetros de entrada
[hz]= iir(n, "lp", "butt",[wc],[])
disp(hz)
a2 = hz.num
b2 = hz.den
[H1, W1]= frmag(a2,b2,512); //frequency response
s = filter(a2,b2,z); // Filtering the signal
S = abs(fft(s)); // frequency response of filtered signal
//[I,T] = impz(b2, a2); //impulse response of filter IIR
//Coeficientes do filtro de butterworth
disp('Coeficientes do filtro de butterworth');
disp(b2);
disp(a2);
这是你想要的吗?