Domanda

Some MatLab code I'm trying to simplify goes through the effort of finding FFT, only to take the absolute value, and then the mean:

> vector = [0 -1 -2 -1 0 +1 +2 +1];
> mean(abs(fft(vector)))
ans = 2

All these coefficients are built up, then chopped back down to a single value. The platform I'm working on is really limited, and if I can get by without using FFT, all the better. Is there a way to approximate these operations without FFT?

Can assume vector will be at most 64 values in length.

È stato utile?

Soluzione

I think this is a just a very inefficient way of calculating the RMS value of the signal. See Parseval's Theorem. You can probably just simplify the expression to:

sqrt(mean(vector.*vector))

Altri suggerimenti

If your vector is real and has zero average as in your example, you can take advantage of the fact that the two halves of the DFT are complex-conjugate (from basic signal processing) and save half the abs computations. Also, use sum, which is faster than mean:

fft_vector = fft(vector);
len = length(fft_vector)/2; 
sum(abs(fft_vector(1:len)))/len
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top