4

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

1
  • 1
    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
    Dec 8, 2010 at 5:19

3 Answers 3

3

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

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

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.

3
  • Signal processing in basic?? Why would anybody want to do that? Dec 8, 2010 at 8:53
  • 1
    Obviously you wouldn't use the Basic code in real applications, but as the book puts it: " learning DSP has very different requirements than using DSP". So Basic in this case serves more as a pseudocode that can be easily translated to any language. Dec 8, 2010 at 10:57
  • @NathanFellman : Basic was the programming language common to all personal computers going on 3 decades ago. So it was a historical lingua franca after Fortran, but before C became more common. And "real" DSP assembly language was usually extremely non-portable.
    – hotpaw2
    Dec 8, 2010 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.