Tuesday, May 17, 2016

Digital Elliptic Filter in Matlab

(Just learning how to use elliptic filter in Matlab)

The elliptic filter works pretty well, so efficient. The following filter will band 50Hz and near frequencies (see the third figure). And the last figure shows the filtered signal.

==== m code started ====

clear
Rp = 5; % peak-to-peak passband ripple, the smaller the smoother
Rs = 60; % stopband attenuation
Fs = 250; % sample rate
Wp = [47, 53]/Fs*2; % passband edge frequency
Ws = [48, 52]/Fs*2; % stopband edge frequency
[N, Wn] = ellipord(Wp, Ws, Rp, Rs); % find the minimum order of the required filter

fprintf('Wn %f, %f\n', Wn(1)*Fs/2, Wn(2)*Fs/2);

[b,a] = ellip(N,Rp,Rs, Wn,'stop'); % design an elliptic filter
freqz(b,a); % draw frequency response of the filter

title(['ellipord Analog bandstop filter order N=',num2str(N)]);
xlabel('Frequency(Hz)');

tseq = 0: 1/Fs :6;
dataIn =  sin(tseq*10 *2*pi) + sin(tseq*50 *2*pi) + sin(tseq*52 *2*pi) + sin(tseq*48 *2*pi);
dataOut = filter(b,a,dataIn);

figure(2);
plot(dataIn);
figure(3);
plot(dataOut);




No comments: