I have raw NIRS signal data measured during a study experiment and I would like to unify the signal lengths to avoid bias in analysis caused by longer signals.

Can I simply cut the samples out from longer signals to do this? Are there any considerations or other methods that should be taken into account?

Example: length of the signals are 2 min, 3 min, 4 min, 6 min. I would modify with the method described the lengths of all signals to be 2 min. This way all the analyzed data is from the start of the measurement until the 2 min sample.

  • 1
    $\begingroup$ Hi, and welcome to SE.DSP! Can you be a little more precise in your question? Mainly, what kind of analysis are you trying to do? $\endgroup$
    – Jdip
    Sep 6, 2022 at 17:19
  • $\begingroup$ May I ask, what kind of features? Frequency-based? time-based? both? $\endgroup$
    – Jdip
    Sep 6, 2022 at 18:45
  • $\begingroup$ @Jdip Thank you! I'd like to do automated feature extraction for the signals and after that select features for machine learning model for a classification task. Right now, I am conducting pre-processing steps. As NIRS is applied to brain, I'd like the signals to be of similar length to avoid effects related to it (e.g. 2min vs 10min, the person measured for 10 minutes could get more bored, irritated etc.) Let me know if I can clarify more. $\endgroup$
    – damalina12
    Sep 6, 2022 at 18:45
  • $\begingroup$ @Jdip Features from both domains. $\endgroup$
    – damalina12
    Sep 6, 2022 at 18:46
  • $\begingroup$ More precisely, the feature extraction methods I'm planning to use are either HCTSA for MATLAB or tsfresh for Python. Both packages extract large number of time-series characteristics. HCTSA: hctsa-users.gitbook.io/hctsa-manual tsfresh: tsfresh.readthedocs.io/en/latest $\endgroup$
    – damalina12
    Sep 6, 2022 at 18:55

2 Answers 2


This is more an ML than SP question, but there's overlap and I've worked with this problem so I'll comment.

This is a problem of information. Lengthening a signal = making something out of nothing. Cutting a signal = tossing contents out. When we're talking time lengths that are double and triple each other, that's excessive and cannot be resolved easily. Three approaches come to mind:

  1. Time-invariant features. Something that completely collapses the time axis. An example is wavelet scattering. Simpler, DFT (FFT), but that's terrible features.

  2. Multi-scale models. Mainly, multi-input networks, each input being different time length, then concatenating later.

  3. Resampling: to same sampling rate. A common approach, and the optimal one if the procedure is perfect (unaliased). Upsampling can work close to ideal, unlike downsampling which can be severely lossy.

  4. Resampling: to same length (but different SR). Works well if done right. Segments A and B can both be 36 samples, but B be twice longer in time. Then, feeding (2, 36) to 1D CNN, which assumes uniformly strided input, may mess up features, more so if there's cross-channel operations along time. It is the norm for images, but images don't care about alignment along a spatial axis, unlike some temporal tasks. This is worth asking about separately, or just testing.

Many tricks can force lengths to be same, but nothing bypasses the problem of information: if lengths become same, some transformation has been done that necessarily changes information contents. This is true even in lossless compression, which preserves synthesis information (recovery) but not analysis information (stability, discriminability, invariance). Hence, if we take a network that "takes care of" lengths for us, e.g. by padding, a close inspection is due.

Another point, task-specific exceptions can be made, e.g. vastly different lengths are okay for telling apart different speakers, but not for predicting what both of them will say at some same instant.

Lastly, a large factor is feature-network synergy: different architectures react differently. For an RNN, left-padding is much preferred to right-padding, while a conv-net doesn't care, for example.

  1. just cutting signals is not recommended because you may lose information.

  2. Padding zeros to the shorter signal may work.

  3. You can also scale time, depending upon what you are looking for, this may or may not work :

Compress y2(t)=y1(k*t) or span y2(t)=y1(t/k) ; k>1 to get the 10 minute signals fit onto the 2 minute ones.

These operations alter ampplitude values on spectrum: The energy of a compressed or spanned signal, keeping time signal amplitude means signal energy is reduced or increased respectively.

  1. However if you cannot extract the information you are looking for in 2 minutes, do you really think that waiting another 8 minutes is going to work?

By this I mean, why not then waiting 15 minute? or 1 hour?

Obviously as you mentioned patients may not put up with long tests, therefore, carrying out tests with always same time span would be the best recommended practice; you can set up standard tests of just a few specific time spans, and then compare only tests with same time span.


Your Answer

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

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