# Perform non-power-of-two FFT using ARM CMSIS library

I have 1280 points which I would like to perform an FFT using a M7 cortex with hard floating point engine.

As the title suggest I would like to use the ARM CMSIS library to perform a non-power-of-two FFT.

As I am not familiar with the library functions or FFTs, I would like to know if this is possible based on the available CMSIS FFT functions.

Can i combine or use the available radix-2, 4 and 8 functions to 'build' what I want? What particular FFT algorithms should i be looking at?

Other options I gather would be to zero pad the signal from 1280 to 2048.

The application is for 3-phase Power System Voltage and Current monitoring (50/60 Hz) at 6.4 kHz sampling rate.

• I would like to average the Harmonics over time (only the integer multiple of fundamental comp) and compare their magnitudes against industry regulated threshold.
• Perform a THD on the harmonics.
• I would like to extract the fundamental component for further processing (symmetrical components calc and unbalance ratios).
• Whether you can zero pad or not depends on what you want to do with the FFT. Can you elaborate on that? Oct 31 '18 at 15:10
• Thanks for your reply. I have multiple use for the FFT output. The application is for 3-phase Power System Voltage and Current monitoring (50/60Hz) at 6.4kHz sampling rate. I would like to average the Harmonics over time (only the integer multiple of fundamental comp) and compare their magnitudes against industry regulated threshold. Perform a THD on the harmonics. I would like to extract the fundamental component for further processing (symmetrical components calc and unbalance ratios). Oct 31 '18 at 15:25
• While I really like the fact that the FFT can give you a nice PSD estimate over a whole bandwidth, you really don't care about what happens throughout most of the 3.2 kHz; only for the harmonics of the $50\pm\epsilon$ Hz, right? So, that would indicate an FFT would produce a lot of data you don't need. In that case, a simple parametric spectral estimator for the exact base tone (50 or 60 Hz plus minus frequency error) and an evaluation of the power at multiples of that frequency would do better, wouldn't it? Oct 31 '18 at 16:01
• How many harmonics do you need? If the number is low, you don't need to perform a full FFT. The Goertzel algorithm is more suited.
– Ben
Oct 31 '18 at 20:00

Here is some code that calculates a 1280 tap FFT based on 5 256 tap FFTs

%% 1280 FFT based on five FFTs of 256 each
n = 1280;
% Create a piece of noise
x = randn(n,1);
% calculate FFT using MATLAB native fft() function.
% We'll use this as a reference to prove it works
fx = fft(x);

% Break down into five signals of 256 points each, interleaved
p = x(1:5:end);
q = x(2:5:end);
r = x(3:5:end);
s = x(4:5:end);
t = x(5:5:end);
% FFT each of those. This is a 256 power-of-two standard FFT
fp = fft(p);
fq = fft(q);
fr = fft(r);
fs = fft(s);
ft = fft(t);
% Do five times periodic extension (just repeat it 5 times)
fp5 = repmat(fp,5,1);
fq5 = repmat(fq,5,1);
fr5 = repmat(fr,5,1);
fs5 = repmat(fs,5,1);
ft5 = repmat(ft,5,1);
% calculate the 1280 twiddle factors
k5 = (0:n-1)';
W5 = exp(-1i*2*pi*k5/n);
% assemble the result
fy5 = fp5 + W5.*fq5 + W5.^2.*fr5 + W5.^3.*fs5 + W5.^4.*ft5;
% calculate the error
ferror = fy5-fx;
fprintf('Error = %6.2f dB\n',10*log10(sum(ferror.*conj(ferror))./sum(fx.*conj(fx))));

• Thanks for this Hilmar. It is a great example. I will do my best to re-code it using CMSIS cfft() function. Oct 31 '18 at 17:01