Apply a bandpass filter in freq domain
76 views (last 30 days)
Show older comments
Hi. I am new to signal processing. Appreciate any help.
I have a signal with too many data points and high sampleing rate (500 MHz). The main goal is discarding the effect of the data outside a certain freq range (10- 100 kHz) for which our instrument is not calibrated. So I think I need to apply a bandpass filter in freq domain. I am not sure if I do that correctly, since after applying this filter, the magnitude of the data outside this range are still not zero and the filter doesn't discard the data outside range and it also changes the values wihtin the range. What is that I am doing wrong?
Here is the code:
fs = 500e6;
f1 = 10e3, f2 = 100e3;
wn = [f1/fs f2/fs];
[b,a] = butter(20,wn,'bandpass');
[H w] = freqz(b,a,length(x)); % x is the main signal
y = fft(x).*(H); % Applying the filter
Thank you
Brad
0 Comments
Accepted Answer
Star Strider
on 6 Apr 2020
‘So I think I need to apply a bandpass filter in freq domain.’
Don’t. That is extremely difficult, since the Fourier transform is symmetrical and it would be necessary to do that on the ‘positive’ as well as the ‘negative’ (complex-conjugate) parts, and so is generally not worth the effort.
Assuming that ‘x’ is your time-domain signal, do this instead:
fs = 500e6;
fn = fs/2;
f1 = 10e3, f2 = 100e3;
wn = [f1 f2]/fn;
[z,p,k] = butter(20,wn,'bandpass');
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos,2^14,fs); % x is the main signal
set(subplot(2,1,1), 'XLim',[0 200E3]) % ‘Zoom’ Plot
set(subplot(2,1,2), 'XLim',[0 200E3]) % ‘Zoom’ Plot
x_filtered = filtfilt(sos,g,x);
The transfer-function implementation of that filter is demonstrably unstable. The second-order-section implementation is stable and will likely do what you want it to.
14 Comments
Star Strider
on 10 Apr 2020
As always, my pleasure! Thank you!
1. The ‘Rs’ and ‘Rp’ are are the stopband and passband attenuations, so ‘Rs’ must always be greater than ‘Rp’ if the filter is to be effective. I do not recall any specific limits on ‘Rs’. (I usually use 50 for ‘Rs’, however there is no specific value for it.) The ‘Wp’ parameter is the passband edge, and defines the filter. (It, in combination with ‘Ws’ define the transition region.)
2. The relation between ‘Ws’ and ‘Wp’ depend on the filter design and where they are in the spectrum, so in a highpass or bandpass filter this is more of a problem if they are close to 0 than if they are higher in the spectrum. (In that instance, I usually choose ‘Ws’ that is half the value of ‘Wp’ for highpass filters or the lower edge of a bandpass filter.) As a general rule, it is best to avoid short/steep transition regions because this will increase filter complexity and can lead to instability. I generally keep the transition regions to about 5% of the passband edges. This depends on the filter, and the results of preliminary experiments with the filter and the particular signal.
3. The 10% criterion works, however I tend to prefer symmetry, so the same transition regions on both sides of a bandpass or stopband filter. It also depends on the filter, so elliptic filters are more likely to be stable with small transition regions than Butterworth designs.
Again, my pleasure!
More Answers (1)
Brad
on 16 Jun 2020
3 Comments
Star Strider
on 16 Jun 2020
1. Both are ‘correct’. The one that most closely meets your requirements is the one to use. I cannot determine that.
2. Use filtfilt with the digitalfilter object if you request it (second output). Those functions use it internally to do the filtering, so it is not necessary to do anything else. If you are filtering several signals, it is easier to use the digitalfilter object than to repeatedly run those functions. You can use the save function to save it to a .mat file to load when necessary later.
See Also
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!