I'm trying to perform an FFT using the CMSIS libraries.

My FFT_Output[] provides 1024 bins of data as expected. The issue is that it's linearly spaced and I want to change it to a logarithmic scale into 64 bins (each of these bins correspond to an LED) as it corresponds with how we hear so looks better. I'm sampling at 44kHz and taking 2048 samples (FFT_Output provides 1024) and using a TM4C1294XL.

I'd like to keep the 'negative' frequencies that the FFT produces for the symmetrical effect that it'll have on the LEDs.

I'm really struggling with how to do this, I've never done logarithms in C. I have no problem scaling it linearly. How could I change this function (which scales lin) to do it logarithmically or is there a better way?

FFT_Output[] - my 1024 result bin[] - my 64 bit bin that corresponds to my LEDs bin_scaled[] - my 64 scaled to 255 (the number needed for my LEDs)

int j;
    for(j=0; j<N_LED; j++)
        int i;
            bin[i/16] += FFT_Output[i];

        arm_max_f32(bin, N_LED, &Bin_maxValue, &Bin_Index);
        bin_scaled[j] = (bin[j]/Bin_maxValue)*255; //this is the array that will be used
  • 1
    $\begingroup$ Can you clarify your question? It sounds like you're asking "How do I calculate the logarithm of a number in C?", which is off-topic here and has multiple related answers in stackoverflow.com/search?q=logarithm+[c] $\endgroup$ – MBaz Apr 23 '16 at 15:31
  • $\begingroup$ CMSIS is an abstraction layer ARM specified for some of their processors; it doesn't define FFTs. Maybe you're talking about some specific compiler/toolchain vendors standard libraries that go under the same name? At any rate, this is a specific programming and not a DSP question and is off-topic here, sorry. $\endgroup$ – Marcus Müller Apr 23 '16 at 16:07
  • $\begingroup$ @MarcusMüller: I guess he is talking about CMSIS-DSP. $\endgroup$ – jojek Apr 23 '16 at 16:34
  • $\begingroup$ Yes, I'm talking about CMSIS-DSP:) No, I'm asking how to scale an entire array logarithmically not the single number. I'm trying to reduce 1024 bins linear to 64 bins logarithmic. Does that clear it up? $\endgroup$ – William Yates Apr 23 '16 at 17:22

You could do something similar to using a Mel triangular filter bank to do a weighted extraction from the longer FFT result vector into your shorter 64 bin log-spaced result vector elements.

  • $\begingroup$ Why not to use N'th octave bands instead? Mel scale is awful and hard to interpret. $\endgroup$ – jojek Apr 23 '16 at 18:20
  • $\begingroup$ Nth (or 12th) octave might work better for music, but the OP didn't specify music, only perceptual. Also, a quick search found no diagram for Nth octave triangular or raised cosine weighting. $\endgroup$ – hotpaw2 Apr 23 '16 at 21:05
  • $\begingroup$ You've got your point. Although I always prefer to use plain N'th octave band spectrum instead of mel/bark/erb scales. It's more intuitive and generalises to all types of signals. Also, it's extremely easy to implement. $\endgroup$ – jojek Apr 23 '16 at 21:21
  • $\begingroup$ Indeed, I'd like to split it into octave bands,if this is possible? (or as close as) $\endgroup$ – William Yates Apr 24 '16 at 10:16
  • $\begingroup$ Same method. Just space the triangular filter bank tops 2^(-N) apart, instead of Mels apart. $\endgroup$ – hotpaw2 Apr 24 '16 at 12:58

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.