# How to perform an FFT on a signal with a sampling rate of 44100?

This is probably a very simple Signal Processing question but I can't quite work it out. I'm currently writing an android app which needs to perform an fft on audio data taken from the phone's microphone. I'm currently reading in the audio data into a byte array buffer at a sampling frequency of 44100Hz.

 int bufferSize = AudioRecord.getMinBufferSize(44100,
AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);

final AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 44100,
AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT,
bufferSize);

final AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC, 44100,
AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT,
bufferSize, AudioTrack.MODE_STREAM);

final byte[] buffer = new byte[bufferSize];
final int finalBufferSize = bufferSize;


Once the buffer has been filled I convert the data to an array of Complex numbers and pass the data into an fft function. My problem is that the fft function I have cannot work with 44100 samples as it requires the length of the array of samples to be a power of 2. I've found what I think are some solutions online but I'm a little unsure if I'm fully understanding them correctly.

As I understand it I can either pad the array out with zeroes in order to make the array length a power of 2 or I can take a fixed fft size, e.g. 1024 samples. If I use the second solution do I need to divide the original array of samples into 1024 chunks and run an fft on each? Any advice on how I should go about this would be appreciated.

Here is the fft class I'm using: http://introcs.cs.princeton.edu/java/97data/FFT.java.html

• why do you need an FFT of 44100 samples? you don't explain that. – Marcus Müller Jul 4 '16 at 15:27
• As in why do I use 44100 or why am I doing the fft? As I understand it sound is usually sampled at 44100. I need the fft because the app needs to determine the pitch of musical notes. – PyroPez Jul 4 '16 at 15:34
• yes, but why 44100? – Marcus Müller Jul 4 '16 at 15:46
• The FFT doesn't care at all at what rate you sampled something – the FFT is just an implementation of the DFT, which really just maps vectors of N samples to other vectors of N samples. It's a linear operation. The question what the elements of the resulting vector signify is something that determines the FFT length. – Marcus Müller Jul 4 '16 at 16:00
• also, by the way, don't use native Java code to do an FFT, if you can avoid it. The FFTw runs perfectly fine on Android on x86 and ARM, and is bound to be orders of magnitudes faster, and will also support very fast FFTs for non-power-of-2 FFT lengths. – Marcus Müller Jul 4 '16 at 16:01