【注】:主要说滤波器的保存和调用。
一、打开App, 找到filter design;
二、根据要求设计你的陷波器;
以阻止50Hz工频为例子,设计的单一陷波器(另外还有comb:梳妆陷波器)
(1)设计
(2)File->Export:
(3)使用这个.mat文件
clear all;
close all;
clc;
%设置初值
f0=50;
Ts=0.001;
fs=1/Ts;
NLen=512;
n=0:NLen-1;
% 加载设计好的陷波器:
load('SingleNotchOne.mat');
x=sin(2*pi*50*n*Ts)+sin(2*pi*125*n*Ts);%原信号
y=dlsim(Num,Den,x);%陷波器滤波处理
%对信号进行频域变换。
xfft=fft(x,NLen);
xfft=xfft.*conj(xfft)/NLen;
y1=fft(y,NLen);
y2=y1.*conj(y1)/NLen;
figure(2);%滤除前后的信号对比。
subplot(2,2,1);plot(n,x);grid;
xlabel('Time (s)');ylabel('Amplitude');title('Input signal');
subplot(2,2,3);plot(n,y);grid;
xlabel('Time (s)');ylabel('Amplitude');title('Filter output');
subplot(2,2,2);plot(n*fs/NLen,xfft);axis([0 fs/2 min(xfft) max(xfft)]);grid;
xlabel('Frequency (Hz)');ylabel('Magnitude (dB)');title('Input signal');
subplot(2,2,4);plot(n*fs/NLen,y2);axis([0 fs/2 min(y2) max(y2)]);grid;
xlabel('Frequency (Hz)');ylabel('Magnitude (dB)');title('Filter output');