I suspect I have a very basic misconception so I'm trying to clarify that here:

A signal should be filtered before it is sampled, correct? That is, I always sample an analogue signal at some sampling frequency after it has already been filtered.

However, MATLAB's butter function acts on sampled data. See the example code here:

[b,a] = butter(6,0.6);
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);

But once you've sampled, the aliases are mixed up with the original signal so isn't this a very problematic way of doing things?

  • 3
    $\begingroup$ You are right, once the signal is already sampled, there is no easy way of removing the aliasing artefacts. When converting from analogue domain to digital, you should use a physical filter, before ADC. Your Butterworth filter has nothing to do with anti-aliasing filter per-se. (Well, unless you want to generate some "fake" analogue signal in MATLAB) $\endgroup$ – jojek Jun 22 '16 at 7:47
  • $\begingroup$ Thank you for your reply. So what does this piece of code actually do? I took it from MATLAB's documentation for Butterworth filtering. I also tried running it on the fft of random noise and noticed that frequencies above the cutoff were attenuated but that seems pointless. $\endgroup$ – user1936752 Jun 22 '16 at 8:00
  • $\begingroup$ @user1936752: Well, you can filter discrete-time signals just like continuous-time signals, and this makes a lot of sense for many applications. Why does that "seem pointless" to you? $\endgroup$ – Matt L. Jun 22 '16 at 8:01
  • 1
    $\begingroup$ @user1936752: You generate a random noise, which contains all frequencies - it's spectrum is flat. Think of that as actually capturing the voltage on a resistor. This thermal noise should be similarly white. In digital domain you will do all sorts of filtering, like here for example, you remove everything above 0.6 of normalized frequency (for $f_s=2000 \mathrm{Hz}$ that is $600 \mathrm{Hz}$). Why would you do that? Imagine that you just captured this signal and you know that all of the information is below that frequency limit - you don't really need the rest. $\endgroup$ – jojek Jun 22 '16 at 8:08
  • 1
    $\begingroup$ @user1936752: You can't really use the fft for that purpose, at least it won't work very well. To understand why, take a look at this question and its answers. $\endgroup$ – Matt L. Jun 22 '16 at 8:14

You're right. That's why your anti-aliasing filter needs to be an analog filter. You need to restrict the bandwidth of the analog filter before sampling.

However, you can do part of the anti-aliasing filtering in the digital domain by first using a higher sampling rate and a simple analog filter, and down-sampling after applying a digital anti-aliasing filter. This is explained in the answers to this question. But in any case you'll need an analog filter first.


You're right, and as Matt already pointed out, you must band-limit, i.e. filter, a signal before you sample it, or else you'll get aliasing.

However, filtering in the digital domain has a lot of of applications.

As a very tangible example, I'll add the following GNU Radio signal processing flow graph:

PFB channelizer

What you need to know is: The "USRP Source" is just an interface to a fast ADC, running at 200 MS/s (with my specific USRP model); the analog signal, which is what the mixer gives us, downconverted from 97.5 MHz to 0 Hz/Basevabd is of course first sufficiently filtered to avoid aliases.

Then, in the FPGA inside the device, there's an adjustable digital filter, which limits the potentially 200 MHz bandwidth (this is a complex signal, so Nyquist rate == sampling rate!) to one eigth of that, and throws away all but one of 8 samples, leading to the 25 MS/s rate that we've requested, and sends that to the PC running this signal processing flow graph. So that's the first usage of a digital filter here¹. It's not a Butterworth filter, though – digital filters in applications are seldom Butterworth, because that is a class of filters designed for a very specific use case – but a combination of multiple half-band Nyquist-M FIRs (which type/design methodology I tend to forget all the time...) and a CIC.

The resulting 25 MS/s enter the PC and are "piped" into GNU Radio. Here, they hit the "Polyphase Channelizer", which is really just a mathematical way of taking the same "prototype" filter, in my case a "select 50 kHz" low-pass filter designed with a window method (and I used a Hamming window here, because well, that's what I did; other windows work, too), and repeating it $N$ times, each time shifted in frequency by $\frac{f_\text{sample}}N$. I asked for $N=20$ equi-distant filters.

So this way, I can now have e.g. 20 parallel (or in fact, 500) e.g. FM demodulators, giving me the audio of all the adjacent 50 kHz channels I expect in my input signal at once.

¹ in fact, there's an optional IIR even before the decimation filter – it's a high pass filter designed to stop DC.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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