How to create a band pass filter

3 views (last 30 days)
Anastasiya Kobrina
Anastasiya Kobrina on 4 May 2015
Answered: Jeremy on 18 Jun 2015
Hi guys,
I would like to pass my .wav file through a band pass filter. I am not sure what order to use. To give an example- my .wav file contains USVs- aka my band is actually from 20 khz to 100 khz (beyond human hearing).
Sampling frequency is 50 kHz
fs = 50e3;
t = linspace(0,1,50e3);
% 1 kHz and 3 kHz sine waves
x = cos(2*pi*1e3*t)+0.5*sin(2*pi*3e3*t)+randn(size(t));
% Lowpass filter everything below 20 kHz
% Specify the filter
hlpf = fdesign.lowpass('Fp,Fst,Ap,Ast',20e3,20.1e3,0.5,50,50e3);
% Design the filter
D = design(hlpf);
% apply the filter
y = filter(D,x);
subplot(211)
plot(t(1:1000),x(1:1000)); title('Original Waveform');
subplot(212)
plot(t(1:1000),y(388:1000+387)); title('Filtered Waveform');
figure;
subplot(211)
plot(psd(spectrum.periodogram,x,'Fs',fs,'NFFT',length(x)));
title('Original Signal PSD');
subplot(212);
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(x)));
title('Filtered Signal PSD');

Accepted Answer

Jeremy
Jeremy on 18 Jun 2015
you discuss a bandpass filter but you are applying a lowpass filter...
Aside from that, the order really depends on what type of data you have and what you are trying to accomplish, I know this doesn't really help. But you basically want to minimize the filter order that will meet your requirements. The higher the order, the higher the ripple and phase shift, so start low.
You are using a filter definition that defines the requirements and the filter order will be a result of those requirements. With Fp and Fst so close this will be a very high order filter.
You are also not specifying the design method, equiripple will be the default.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!