design band pass filter

조회 수: 16 (최근 30일)
Natalia Przedborska
Natalia Przedborska 2020년 6월 4일
답변: Star Strider 2020년 6월 4일
Hello,
I have to design bandpass filter of 2-5kHz band, filter length 100. Then I have to filter with it the white noise and one other signal (triangle, sawtooth, square, f=500Hz).
Previously I designed a low pass filter and filter through it white noise (code below), I wonder if I could modify the code to fit the band pass or should I design it other way. Maybe filter designer? But how to later filter with it the signals? Please help me, I'm struggling with Matlab :(
rng default
Fs = 1000;
t = linspace(0,1,Fs);
x = randn(size(t));
fc = 150;
Wn = (2/Fs)*fc;
b = fir1(20,Wn,'low',kaiser(21,3));
fvtool(b,1,'Fs',Fs)
y = filter(b,1,x);
plot(t,x,t,y)
xlim([0 0.1])
xlabel('Time (s)')
ylabel('Amplitude')
legend('Original Signal','Filtered Data')

채택된 답변

Star Strider
Star Strider 2020년 6월 4일
Here is prototype code I used for a different project that you can adapt, if you want an IIR filter:
Fs = 250; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Ts = 1/Fs; % Estimate Sampling Interval
t = linspace(0, numel(EKG), numel(EKG))/Fs;
Wp = [2 90]/Fn; % Normalised Passband (Passband = 2 Hz To 90 Hz)
Ws = [1 100]/Fn; % Normalised Stopband (Passband = 1 Hz To 100 Hz)
Rp = 1; % Passband Ripple/Attenuation
Rs = 50; % Stopband Ripple/Attenuation
[n,Wp] = ellipord(Wp, Ws, Rp, Rs); % Calculate Elliptic Filter Optimum Order
[z,p,k] = ellip(n, Rp, Rs, Wp,'bandpass'); % Elliptic Filter
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Sections For Stability
figure
freqz(sos,2^16,Fs)
filtered_signal = filtfilt(sos,g,signal);
There are a number of FIR designs on Answers as well (I have posted many of them), although I usually reserve those for filters with multiple passbands and stopbands.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by