If I have a set of signals each with $n$ points, I can take the DFT of each and then use the resulting frequency domain vectors as features for some classification algorithm. If the signals are differing lengths, the frequency basis used by the DFT is no longer the same. This means I can no longer directly use DFT as features if I want to compare signals of varying length. What should I do about this?

In other words, I want to convert each audio signal into a length $m$ vector of frequency components, and use the same $m$ for all signals.

I realise there is fundamentally more information in a longer signal, so any conversion will involve some loss of information.


As you explicitly mention, that you are aware of a loss of information and are willing to accept that, a possible solution will be modulo-N reduction or wrapping, as described by Orfanidis in the freely available book "Introduction to Signal Processing" on pages 489ff.

In modulo-$N$ reduction, a vector $x$ with length $L > N$, where $N$ is the DFT length, is divided into non-overlapping blocks of length $N$. These blocks are summed up, resulting in one vector $\tilde{x}$ of length $N$ .

modulo-n Figure taken from Orfanidis (linked above), Fig. 9.5.1 on page 489.

You then apply the DFT on $\tilde{x}$, which results in $\tilde{X} = \text{DFT}\{ \tilde{x} \}$ with length $N$. Orfanidis proves that $\tilde{X}$ is exactly equal to the $N$-point DFT of $x$, so is equal to $X$.

In your case, that would mean you could find a minimal length $N$, which is guaranteed for all input signals. You then apply a modulo-$N$ reduction on all your input signals and compare these length-$N$ DFTs. Of course, a higher resolution would be possible for longer signals, and you just ignore this by using the modulo-$N$ reduction method.

Similarly, you could just zero-pad all signals to a maximal length $M$. All your signals will then have a high frequency resolution defined by $M$. Important point: you do have that computational frequency resolution, but the physical frequency resolution is still determined by the length of your signals $L$. More details on this are given in any decent signal processing class or on pages 482ff in Orfanidis.

  • $\begingroup$ In an attempt to add a bit of clarification to his important last paragraph, hbaderts phrase "computational frequency resolution" means the frequency spacing between DFT frequency-domain samples (measured in Hz). I believe his phrase "physical frequency resolution" means the ability to resolve (to recognize the existence of) two separate signals that may exist in a sequence of DFT spectral magnitude samples. $\endgroup$ Aug 26 '15 at 23:20
  • $\begingroup$ Thanks for the link. I think I am missing something - aren't you effectively just averaging the signal? What if the second slice is the negative of the first and they sum to zero? $\endgroup$
    – akxlr
    Aug 27 '15 at 2:48

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.