我正在尝试过滤音频信号,但无法在scilab中找到IIR过滤器函数,可以将其与代码的其他函数结合使用以给出分子和分母,我称之为b2和a2(2°部分)。
我尝试使用zpbutt函数,但是对我没有用,还尝试了analpf()函数
//Code to filter a audio called sirene.wav
clc;
clear;
close;
//Load the audio
wavread("C:\Users\kaline\Desktop\Disciplinas\2019.1\PDS\2° etapa\Trabalho final\sirene.wav","size")
[y,fs,bits]=wavread("C:\Users\kaline\Desktop\Disciplinas\2019.1\PDS\2° etapa\Trabalho final\sirene.wav");fs,bits
y=loadwave("C:\Users\kaline\Desktop\Disciplinas\2019.1\PDS\2° 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的类型错误:需要实数矩阵或多项式。
答案 0 :(得分: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);
这是您想要的吗?