I have multiple signals each measured with a sampling rate 300Hz. They are mostly periodic, although there are some parts of some of the signals, that seem to be random and do not follow the rest of the pattern(could be noise). I want to downsample this signal and I have found these three functions: decimate, resample_poly, and resample.

I do not know much about signal processing, so I was wondering whether someone could explain in simple terms what is the difference between the three functions and if possible suggest which would be the most appropriate to use for my case.

Note that I would like to apply machine learning methods to classify new signals to 2 categories. I need to downsample to decrease the time it takes to classify signals.

  • $\begingroup$ Can I please ask what might follow decimation? What sort of features are you planning to use? How long are these signals? $\endgroup$
    – A_A
    Commented Nov 28, 2017 at 13:16
  • $\begingroup$ I am planning on doing k-NN classification with DTW as a distance metric. They are about 18000 samples each. I measured the frequencies using FFT and it seems that all coefficients are 0 after about 50Hz $\endgroup$
    – Andreas G.
    Commented Nov 28, 2017 at 13:30

1 Answer 1


Downsampling and upsampling are operations that change the sampling rate of a signal. Each one of them is composed of two steps, changing the sampling rate and filtering. Usually, the amount of change is expressed as a ratio.

When downsampling, we are trying to take the signal from some $Fs$ to some $Fs_n < Fs$. The key problem with doing this is that we are effectively reducing the available bandwidth. Therefore, if we were to leave any frequency $f > \frac{Fs_n}{2}$ within the resampled signal, we would get aliasing.

Aliasing is a byproduct of sampling and it distorts the original signal. In DSP, we are trying to minimise it.

Therefore, when Downsampling, we first apply a low pass filter to the signal at its $Fs$ rate. This filter suppresses all frequencies that might cause aliasing. After applying the filter, we apply decimation. Decimation is a very simple process by which we are throwing away samples. For example, to downsample by $\frac{1}{2}$ you throw away every other sample (i.e. keep 0,2,4,6,8,...).

When upsampling, we are trying to take the signal from some $Fs$ to some $Fs_n > Fs$. The key problem now is not that we can't fit the amount of original data to the new bandwidth but the exact opposite. We now do not have enough data.

Sampling works by examining the value of a continuous signal at discrete times, specifically $Fs$ times per second. But, we don't really know what exactly does the original signal do in between those discrete instances we are examining its value.

Therefore, when upsampling, we first upsample, which is an operation that inserts silence in between the samples and then apply interpolation to make up the signal values during the silence bits. Interpolation is usually another low pass filter.

Obviously, we can use both of these operations to change the $Fs$ by any given ratio. But, no matter what this ratio is we first upsample and then downsample (with each upsample, downsample step composed of their own steps mentioned above). Otherwise, you are throwing away information.

So, having said this:

  1. Decimate does downsampling.

  2. Resample does upsampling / downsampling and the associated filtering, entirely in the frequency domain, using the Fourier Transform. Because it is using the Fourier Transform, a key assumption is that the signal that is fed in its input is periodic. In other words, if you supplied a recording of the word "Blue is a co", the Fourier Transform assumes that in reality, the signal sounds like "Blue is a coBlue is a coBlue is a coBlue is a coBlue is a coBlue is a coBlue is a co"...to infinity. This explains the Note towards the end of that page.

  3. Resample_poly does upsampling / downsampling and the associated filtering, using a polyphase filter](https://en.wikipedia.org/wiki/Polyphase_quadrature_filter). (Notice the series of operations applied as mentioned in the documentation).

2 and 3 are essentially the same thing with different techniques for reasons of computation speed. In the techniques mentioned, filtering and decimation and upsampling and interpolation are performed in one step because they are inherent to the technique.

As you can see, changing the sampling rate involves throwing away information or "diluting" the information that was already captured in some signal $x$ during its acquisition at some $Fs$. This is why I asked you what are you going to do after the decimation because under certain conditions, your classification/ clustering might be affected if those tiny little characteristics of signals that differentiate them from each other are smoothed out.

By what you are mentioning, if your highest non-negligible frequency component is at 50Hz, this means that (theoretically), you can reduce your $Fs$ by $\frac{1}{3}$. In practice, try not to get too close to a lowest $Fs$ of 100Hz. Maybe leave some lee-way, say 120Hz.

Hope this helps.

  • 2
    $\begingroup$ Great detailed explanation! If I understand correctly, I guess the safest option here would be Resample_poly since it does not have the requirement that the input is periodic. Mine is mostly periodic but resample_poly can handle that correctly. Would you agree with my conclusion? $\endgroup$
    – Andreas G.
    Commented Nov 28, 2017 at 18:23
  • 1
    $\begingroup$ Thanks, you can upvote and / or accept the answer via the controls on the left if you felt that it was helpful. The answer to this given what is mentioned in your comment is probably "yes" but, I don't think that would be accurate without some more knowledge about the data. Another thing that was going through my mind was whether or not you have to use the entire captured signal (?). Maybe you can split it into overlapping windows (?). What sort of data are we talking about if I may ask? $\endgroup$
    – A_A
    Commented Nov 28, 2017 at 18:36
  • $\begingroup$ It's an echocardiogram. I thought about just using a part of the signal but I am not sure what do you mean I could split it into overlapping windows. Could you elaborate? I've thought about having a sliding window and for each sample use the part that maximizes this metric: stackoverflow.com/questions/47351483/… $\endgroup$
    – Andreas G.
    Commented Nov 28, 2017 at 19:05
  • $\begingroup$ "Sliding window" is the same thing. Are you trying to detect arhythmia? $\endgroup$
    – A_A
    Commented Nov 28, 2017 at 19:47
  • $\begingroup$ I am actually not exactly sure what I am trying to detect. All I know is that one is healthy and the other is not. It's kind of a data driven approach where I am given the data with some labels and I need to build the classifier. $\endgroup$
    – Andreas G.
    Commented Nov 28, 2017 at 19:58

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.