|
这里给出一个陷波器的例子:
% 50Hz notch filter
% sample frequency=400
%
clear all;
clc;
b=[1 -sqrt(2) 1];
a=[1 -sqrt(2)*0.999 0.999];
[db, mag, pha, grd, w]=freqz_m(b, a);
subplot(221); plot(w*200/pi, db); title(' Magnitude Response' );
xlabel('frequency in Hz'); ylabel('dB'); axis([0, 100, -200, 5]);
set(gca, 'XTickMode', 'manual', 'XTick', [0, 50, 100]);
set(gca, 'YTickmode', 'manual', 'YTick', [-200, -100, 0]); grid
title('Notch filter response');
t0=1:8000;
t=1:256;
t1=1:100;
t2=1:128;
x=sin(2*pi*50*t0/400)+0.5*sin(2*pi*100*t0/400);
x1=x(t);
y=filter(b,a,x1);
subplot(222); plot(x1);
title('Original waveform');
X=fft(x1);
subplot(223); plot(t2*400/256,abs(X(t2)));
xlabel('frequency in Hz'); ylabel('|H|'); axis([0, 200, 0, 150]);
title('Spectrum for original');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 50, 100, 150]);
set(gca, 'YTickmode', 'manual', 'YTick', [50, 100]); grid
y=filter(b,a,x);
x1=y(t+7600);
X=fft(x1);
subplot(224); plot(t2*400/256,abs(X(t2)));
xlabel('frequency in Hz'); ylabel('|H|'); axis([0, 200, 0, 150]);
title('Spectrum after filter');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 50, 100, 150]);
set(gca, 'YTickmode', 'manual', 'YTick', [50, 100]); grid |
评分
-
1
查看全部评分
-
|