用切比雪夫最佳一致逼近设计线性相位FIR带通滤波器;
%信号为0.5hz,
0.9hz,
1.1hz和1.5hz的正统信号叠加组成
%通带为[0.9,1.1]
%频谱分辨率与信号实际长度N成正比
clear
all
f1=0.5f2=0.9f3=1.1f4=1.5t=0:1203N=length(t)fs=10M=512
x1=sin(2*pi*(f1/fs)*t)+sin(2*pi*(f2/fs)*t)+sin(2*pi*(f3/fs)*t)+sin(2*pi*(f4/fs)*t)
figure(1)
subplot(211)plot(t,x1)title('原信号')
y=fft(x1)
f=(0:1/N:1/2-1/N)*fs
subplot(212)plot(f,abs(y(1:N/2)))gridxlabel('hz')%处理前频谱
wc1=2*f2/fswc2=2*f3/fswc3=2*f4/fs%归一化角频率,用于下面的f1
f1=[0
wc1-0.05
wc1
wc2
wc2+0.05
1]
A=[0
0
1
1
0
0]%设置带通或带阻,1为带通,0为带阻
weigh=[1
1
1
]%设置通带和阻带的权重
b=remez(60,f1,A,weigh)%传函分子
h1=freqz(b,1,M)%幅频特性
figure(2)
f=(0:1/M:1-1/M)*fs/2
subplot(211)plot(f,abs(h1))gridtitle('带通')
x2=filter(b,1,x1)
S1=fft(x2)
f=(0:1/N:1/2-1/N)*fs
subplot(212)plot(f,abs(S1(1:N/2)))gridxlabel('hz')%处理后频谱
short h[], short y[]){
int i, j, sum for (j = 0j <100j++) {
sum = 0
for (i = 0i <32i++)
sum += x[i+j] * h[i]
y[j] = sum >>15
}
}
2
void fir(short x[], short h[], short y[])
{
int i, j, sum0, sum1
short x0,x1,h0,h1 for (j = 0j <100j+=2) {
sum0 = 0
sum1 = 0
x0 = x[j]
for (i = 0i <32i+=2){
x1 = x[j+i+1]
h0 = h[i]
sum0 += x0 * h0
sum1 += x1 * h0
x0 = x[j+i+2]
h1 = h[i+1]
sum0 += x1 * h1
sum1 += x0 * h1
}
y[j] = sum0 >>15
y[j+1] = sum1 >>15
}
}
3
void fir(short x[], short h[], short y[])
{
int i, j, sum0, sum1
short x0,x1,x2,x3,x4,x5,x6,x7,h0,h1,h2,h3,h4,h5,h6,h7 for (j = 0j <100j+=2) {
sum0 = 0
sum1 = 0
x0 = x[j]
for (i = 0i <32i+=8){
x1 = x[j+i+1]
h0 = h[i]
sum0 += x0 * h0
sum1 += x1 * h0
x2 = x[j+i+2]
h1 = h[i+1]
sum0 += x1 * h1
sum1 += x2 * h1
x3 = x[j+i+3]
h2 = h[i+2]
sum0 += x2 * h2
sum1 += x3 * h2
x4 = x[j+i+4]
h3 = h[i+3]
sum0 += x3 * h3
sum1 += x4 * h3
x5 = x[j+i+5]
h4 = h[i+4]
sum0 += x4 * h4
sum1 += x5 * h4
x6 = x[j+i+6]
h5 = h[i+5]
sum0 += x5 * h5
sum1 += x6 * h5
x7 = x[j+i+7]
h6 = h[i+6]
sum0 += x6 * h6
sum1 += x7 * h6
x0 = x[j+i+8]
h7 = h[i+7]
sum0 += x7 * h7
sum1 += x0 * h7
}
y[j] = sum0 >>15
y[j+1] = sum1 >>15
}
}
窗函数设计低通滤波器:fp=1000
fc=1200
as=100
ap=1
fs=22000
wp=2*fp/fs
wc=2*fc/fs
N=ceil((as-7.95)/(14.36*(wc-wp)/2))+1
beta=0.1102*(as-8.7)
window=Kaiser(N+1,beta)
b=fir1(N,wc,window)
freqz(b,1,512,fs)
高通滤波器:
fs=22000
Wp=2*5000/fs
Ws=2*4800/fs
Ap=1
As=100
N=ceil(8*pi/(Wp-Ws))+1
N=N+mod(N+1,2)+1
Wc=(Wp+Ws)/2/pi
h=fir1(N,Wc,'high')
omega=linspace(0,pi,512)
freqz(h,1,omega)
带通滤波器:
fs=22000
Wp1=2*1200/fs
Wp2=2*3000/fs
Wc1=2*1000/fs
Wc2=2*3200/fs
Ap=1
As=100
W1=(Wp1+Wc1)/2
W2=(Wp2+Wc2)/2
wdth=min((Wp1-Wc1),(Wc2-Wp2))
N=ceil(11*pi/wdth)+1
b = fir1(N,[W1 W2])
freqz(b,1,512,fs)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)