4
votes

I have an array of data, it is in time domain. Each data stands for the magnitude, and that data is sampled in a frequency of 10,000Hz.
I want to do a band pass filter between two frequencies f1, and f2. I think I need to do a low pass filter and a high pass filter. The signal does an FFT then goes through the two filters then do an inverse FFT.
My questions: is there an easy way to do the low pass and high pass filter? I don't know how to derive the transfer function based on the two cut off frequencies.

Does anyone know how?

Thanks

3
In order to get a realistic, fully specified filter of reasonable quality, you might also want to spec stop-band attenuation(s), pass-band ripple, and transition widths. Whatever you do, don't just zero some bins of the FFT.hotpaw2

3 Answers

3
votes

Building on Tristan's answer, here is some Octave Code which might or might not be Matlab compatible. The butter function derives the transfer function coefficients for you. alt text.alt text

hz = 8000;
x = [1:1:hz*10];
t = x./hz;
pi = 3.1415;

% Create signal with 10 hz, 200 hz and 500 hz components
raw_signal = sin(10*2*pi*t)+sin(200*2*pi*t)+sin(500*2*pi*t);

% View Raw Signal Over .1 Second Window
plot(t, raw_signal)
title('Raw Signal with 10Hz, 200Hz, 500Hz Components')
xlabel('Time (Sec)')
ylabel('Amplitude')
set(gca,'XLim', [5, 5.1]);

% Create Band Pass Butterworth Filter
[S_numer, S_denom] = butter(5, [100/hz 350/hz]);
band_passed_signal = filter(S_numer, S_denom, raw_signal);

% View Band Pass Filtered Signal Over .1 Second Window
plot(t, band_passed_signal)
title('Band Pass Filtered Signal')
xlabel('Time (Sec)')
ylabel('Amplitude')
set(gca,'XLim', [5, 5.1]);
2
votes

MATLAB has tools that will do filtering so you don't need to do the FFT-IFFT thing yourself (which can lead to some problems). Try using a combination of butter and filter to do what you want to do.

Butter

Filter

2
votes

If you have signal processing toolbox I suggest you design your filter using the sptool, its a GUI tool for filter design that also shows you the amplitude and phase response etc. What you wan't is a bandpass filter. It can also be constructed from a lowpass and highpass filter as you suggest, but Matlab can also give you the bandpass filter directly.

If you don't have the toolbox I suggest you refer to The Scientist and Engineer's Guide to Digital Signal Processing, the whole book is available online and has lots of good example code in Basic, which is easy to translate to Matlab. e.g Designing bandpass windowed sinc filter.