0

I recently visited this page in order to determine the frequency from signal data in MATLAB:

Determine frequency from signal data in MATLAB

And in this page, an answerer responded with the following code:

[maxValue,indexMax] = max(abs(fft(signal-mean(signal)))); 

From what I can see, a Fast Fourier Transform is taken on a signal named signal, its magnitude is kept by using 'abs', and the max value is computed. The max value will be in maxValue, and the indexMax will contain the position of the maxValue. However, can someone explain what is meant by signal-mean, and what the purpose of it?

Community
  • 1
  • 1
Andrew T
  • 783
  • 4
  • 11
  • 20
  • 1
    Try `x = 1:numel(signal); plot(x,signal,x,signal-mean(signal),'r')` to visually see what it does – Dan Jul 30 '14 at 07:27

2 Answers2

3

It basically normalize the vector signal so it has mean zero (subtracts the mean from signal). So signal - mean(signal) looks like signal except that is shifted on the y axis so it has a zero mean. Hope it is clear.

In the example you posted in the link, the mean of the signal is around -2, so by subtracting the mean you end up with a the signal shifted up around the y=0 axis.

vsoftco
  • 55,410
  • 12
  • 139
  • 252
  • +1 - Correct. This detrends the mean so that the signal is more or less centred at 0 and would thus make the signal centred at `y=0`. – rayryeng Jul 29 '14 at 23:38
3

As stated in vsoftco's answer, signal-mean(signal) subtracts the mean of the signal.

However, the key point is: why is this is done? If you don't subtract the mean, it's very likely that the maximum peak in the FFT appears at frequency 0 (DC component). But you don't want to detect that as the "frequency" of your signal, even if it truly is the highest spectral component. So you remove that zero-frequency component by subtracting the mean. That way, the max operation will detect the maximum non-zero frequency component, which is probably what you want.

Community
  • 1
  • 1
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147