3
$\begingroup$

This is a cross posting from the crossvalidated stack exchange as I thought this may be a better forum to ask.

I have a dataset consisting of respiratory time series signals of different lengths obtained from different groups of patients. I want to either classify or cluster the patients using these timeseries by using the commonalities of the time series of each group. However, I have no experience in dsp.

  1. Firstly, I am confused if I am supposed to filter my signals to get rid of any frequencies above the Nyquist frequency. My sampling frequency is 32Hz and my time series is somewhat noisy and has some artifacts. I am also unsure of which filter to select for this.

  2. Secondly, I wanted to look at the periodogram and the average power spectral density at each frequency within a group - but I am not sure if I understand the periodogram very well - if I have different time series lengths then my periodogram length will vary too, so I am not sure how this comparison can be made.

Being from Pure Math, I know Fourier analysis purely from the perspective of functions and using Fourier transforms to obtain the coefficients that describe the projection of these functions onto an orthonormal system. With periodograms however, I noticed that the x-axis represents sample frequencies. I am confused with the distinction between sampling frequencies vs. underlying frequencies of the generating function (say I have $\sin(2\pi x)$ sampled at 10Hz, does the periodogram characterize the 1Hz underlying frequency of the function?)

Any resources on understanding how to analyze and remove noisy components of time signals from a machine learning perspective would be much appreciated! Due to time constraints, I have shied away from long textbooks on digital signal processing. Thanks a lot.

$\endgroup$
3
  • $\begingroup$ This is not on-topic, but: You're in a hazardous area; been there. Especially if you are dealing with people with respiratory problems. You need the Capnometry Atlas (name might be wrong), that I had, and reference designs from the past. If you are under time pressure, I would definitely hire a capnometry consultant (probably a retired doctor); not a EE like me :) These signals are tough and (justifiably) subject to legal oversight. You have to deal with the patients and the experience/expectations of medical professionals with years of experience. $\endgroup$
    – rrogers
    Dec 16 '20 at 12:25
  • $\begingroup$ The given answers are correct, be aware that any out-of-band leakage gets "aliased" into your signal band and lead to incorrect analysis. $\endgroup$
    – rrogers
    Dec 16 '20 at 13:14
  • $\begingroup$ Additional you can read ncbi.nlm.nih.gov/pmc/articles/PMC5464224 Frequency ventilation is rated as having 40Hz primary. Of course, it's artificial, but I think occasionally used and it would be a "signal". $\endgroup$
    – rrogers
    Apr 20 at 19:23
4
$\begingroup$

Firstly, I am confused if I am supposed to filter my signals to get rid of any frequencies above the Nyquist frequency. My sampling frequency is 32Hz and my time series is somewhat noisy and has some artifacts. I am also unsure of which filter to select for this.

That ship has sailed.

Let $S=\left\{\left.\alpha e ^{i(\omega t+\varphi)}\right|\alpha > 0, 0\le \varphi <2\pi, \omega \in \mathbb R\right\}$, i.e. the set of all distinct complex sinusoid with an amplitude, frequency and phase.

Then $(S,\cdot)$ is a commutative semigroup (proof trivial).

Introducing the equivalence relation $\sim: a\sim b \iff a\left(\frac{n}{r}\right)= b\left(\frac{n}{r}\right) \forall n\in\mathbb Z$ ("two signals are identical after sampling with rate $r$"), we see that signals $s_l=\alpha e^{i(\omega_l t + \varphi)}, l=1,2,\ldots$ are $s_1\sim s_2$ if $\frac{\omega_1-\omega_2}{2\pi}=nr, n\in\mathbb Z$, i.e. we can't tell signals apart after sampling if their frequency differed by a multiple of the sampling rate.

Let's formalize this: $T=\left\{\alpha e^{i([ft+\phi]\mod 2\pi)}\right\}$ is a quotient semigroup of $S$, i.e. $T\preceq S$, and each of the elements is a leader of a $\sim$-equivalence class – and this homomorpism $S\mapsto T$ is in fact sampling, which, as we can see above, is not bijective.

Hence, all the original frequency components from $S$ got mapped to some component from $T$ with frequency normalized to the sampling frequency. That mapping is called aliasing.

What an anti-alias filter $h$ does is

$$h(s): S\mapsto S, h=\begin{cases} s, & f< f_\text{nyquist}\\ 0 & \text{else,} \end{cases} $$

and as you'll figure out when inserting $h(s)$ above is that this yields only the elements that are not aliased to a different frequency.

Thus, everything that "survives" $h$ will also "survive" aliasing without undergoing a change in frequency.

So, if you needed an anti-aliasing filter, it's now too late. Go and do your recording again.

Secondly, I wanted to look at the periodogram and the average power spectral density at each frequency within a group - but I am not sure if I understand the periodogram very well - if I have different time series lengths then my periodogram length will vary too, so I am not sure how this comparison can be made.

In that case, the periodogramm is not a useful mapping on its own – you'll need to add something like a truncation / padding operation to bring all signals to the same duration, for example. At which point the periodogram doesn't seem to be a sensible approach anymore.

$\endgroup$
15
  • 1
    $\begingroup$ Ooh thanks for the wonderful explanation! One more question I have now: say I want to downsample my signal to make computations easier (Currently I cannot run anything on multiple signal with more than 1million samples). My sampling frequency is 32 Hz and I want to go down to 8Hz. From what I've read, I have to decimate this and remove frequencies that lie above 4 Hz. However, in the literature on respiratory signals, they used an iir Butterworth lowpass filter of 1.2 Hz to reduce frequencies to the domain of interest. Now I am confused on what order these two operations should be done in? $\endgroup$
    – Merry
    Dec 10 '20 at 21:53
  • 1
    $\begingroup$ I don't know what you're doing with your signal, but I promise that a 32 Hz sampling rate is laughably low, and computational efficiency doesn't play a role here; all humans ever attached to a breathing analysis device could never breathe enough for this to ever become "much data" for a modern PC... If you want to decimate, the same sampling approach applies, and you hence must filter before you decimate, not after. And a Butterworth doesn't seem to be an appropriate filter choice here. $\endgroup$ Dec 10 '20 at 21:56
  • 1
    $\begingroup$ Marcus, great pure-math answer , for pure math Merry. ;-) Btw. respiration rate is actually quite low (one breath per second? Or even less ) so 32 Hz may be more than sufficient, and even devoid of much aliasing artefacts, depending on which aspect of breathing s/he wanted to capture... Is it the pressure change on some input/output air? Or is it the air flow rate ? That's a sufficently slow signal I suppose.. $\endgroup$
    – Fat32
    Dec 10 '20 at 22:05
  • 1
    $\begingroup$ a Butterworth filter is a good choice if you want flatness of the filter impulse response in the pass band; it's not a good choice if you need fast transition from pass band to stop band or very good attenuation in stop band. $\endgroup$ Dec 10 '20 at 22:05
  • 1
    $\begingroup$ @Fat32 It's supposed to be airflow :) and indeed, I quite enjoyed that answer! $\endgroup$
    – Merry
    Dec 10 '20 at 22:06
3
$\begingroup$
  1. The Fourier transform of a sampled (discrete time) signal can only have information between -Fs/2 and +Fs/2, and that information repeats such that X(f +Fs) = X(f), such that Fs is the sampling frequency. This means that when sampling an analog signal, you probably want to low pass that signal to make sure it has no frequencies above Fs/2, the Nyquist frequency. This must be done on the analog signal. If the analog signal does have frequencies above Nyquist, they will ‘alias’, and nothing can be done about it after sampling, unless you know something clever about the signal, but that’s more of a corner case.

  2. Periodograms have a length and hop size. The longer the length, the higher the frequency resolution but lower time domain bandwidth. The hop size sets the time domain resolution. So you can resolve 1Hz with a 10Hz sample rate provided the length is sufficient.

Sorry, I don’t do any machine learning stuff, so can’t help there.

$\endgroup$
4
  • $\begingroup$ Thanks for your feedback! So to clarify, if the signal is already recorded, i.e. I have the signal as an array in a dataset, an anti aliasing filter is not required? $\endgroup$
    – Merry
    Dec 10 '20 at 20:15
  • 1
    $\begingroup$ @Merry it's no longer possible. It might have been required, and you just recorded unusable data... $\endgroup$ Dec 10 '20 at 21:07
  • $\begingroup$ Ah I see - I think I had a fundamental misunderstanding of when this filtering is done. Are there any concise resources you could recommend on practical signal processing? Thanks a lot for your help. $\endgroup$
    – Merry
    Dec 10 '20 at 21:15
  • 1
    $\begingroup$ @Merry The Engineers and Scientists Guide to DSP is free and worth well more than the price. I’d start with that. $\endgroup$
    – Dan Szabo
    Dec 11 '20 at 2:45

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.