Get the frequency from a vector in the frequency domain

Asked

Viewed 533 times

4

I was looking at the following topics:

https://stackoverflow.com/questions/7674877/how-to-get-frequency-from-fft-result

https://stackoverflow.com/questions/7649003/jtransforms-fft-in-android-from-pcm-data

They explain how to perform the transform in order to obtain the frequency of a sound. It uses a library that takes as input a double vector in the time domain and returns a vector in the frequency domain using the method realForwardFull(); So if I have a vector in the domain of time (audioDataArray), each position of this vector has a magnitude value and when making the transform, the vector is in the domain of frequency:

DoubleFFT_1D.realForwardFull(audioDataArray);
  1. In the time domain each position is the magnitude and the index indicates the tempo(x=índice; y = magnitude) from what I could understand. In the frequency domain, after applying the transform, the values of each vector position continue to be the magnitude(y)? What the indices represent?

To find the fundamental frequency it counts the following for each vector position and compares to see which has the highest value (magnitude):

Magnitude = sqrt(re*re + im*im)

Finding the index that has the highest magnitude he makes next account to find the fundamental frequency:

Frequency = Fs * i / N

Where:

Fs = sample rate (Hz)
i = index of peak
N = number of points in FFT (1024 in this case)
  1. I didn’t understand this account: Why to find the fundamental frequency you have to multiply the index by the sampling rate and divide by the number of vector positions?

1 answer

5

Come on lol grasshopper

The Fourier transform will return you real and imaginary units, it is very important that you understand complex numbers and discrete mathematics.

Answering your questions:

In the time domain each position is the magnitude and the index indicates the time(x=index; y = magnitude) as far as I can understand. In the domain of frequency, after applying the transform, the values of each vector position continue to be magnitude(y)? What represents the indexes?

Y = return of the values computed by the Fourier transform, values of the spectral components, these values can be used to find the Magnitude, for this it is necessary to extract the real and imaginary part of the values returned by the transform, to find the magnitude from the values of the transform it is necessary to calculate the square root of the real part squared plus the imaginary part squared...

(sqrt((real(FFT).*real(FFT))+(imag(FFT).*imag(FFT))))

Therefore the Y initial is not the magnitude o Y is the return of the transform, the magnitude you found with the equation above, you can still use an equation derived from the one shown above and convert the values into decibels, can also use the values of the transform to calculate different types of descriptors, or find the phase of the analysed signal.

X = Indexes of each calculated spectral component, this means that when you look at a Plot of the magnitudes in the frequency domain, you are observing all the frequencies that make up your signal and their respective magnitudes, therefore x = período, this is very important, a transformada de Fourier de um sinal periódico gera um espectro discreto no domínio da frequência, that is, it is extremely useful to perform analysis on repeating signals in an interval of time T, clear can be used to find frequency patterns in any type of information/data.

The index X(think how period) has a resolution order that depends entirely on the sample size analyzed by the Fourier transform, if you send a sample size equal to 4096 shall have a resolution order of 2.4414e-04 = 0.00024414062, in your basic physics classes you should remember that the frequency and period of a wave is equal f = 1/T applying we will have 1/4096 = 0.00024414062, the shorter the resolution order, the more precise the periodicity...

I did not understand this account: Why to find the fundamental frequency has to multiply the index by the sampling rate and divide by the number of vector positions?

With the hand sampling rate + the number of vector samples sent to Fourier it is possible to know what the corresponding frequencies are in each X

So each index corresponds to a frequency, let’s imagine that you generate 4096 spectral components and that the sampling rate of your audio is 44100hz, That would give you a resolution order = 44100/ 4096 = 10,7666015625hz or if you prefer (1/4096) * 44100 = 10,7666015625hz

This means that the accuracy of each component is close to 11hz by difference, roughly you may be missing a frequency in the accuracy of 11hz in each of the 4096 indices/components, before that you have to know that there is a theorem called Nyquist, it defines that to reconstruct a signal with minimum loss of information the sampled frequency must be equal to or greater than twice the higher frequency of the spectrum of that signal, if our sampling frequency is 44100hz then the highest frequency possible within this signal will be 44100/2=22050hz, but then how to know which frequencies I will have in each spectral component of the series Fourier:

  índice/componente 1 -> 10,7666015625000hz

  índice/componente 2 -> 21,5332031250000hz

  índice/componente 3 -> 32,2998046875000hz

  índice/componente 4 -> 43,0664062500000hz

  índice/componente 5 -> 53,8330078125000hz

    …

    …

    …

  índice/componente  2047 -> 22039,2333984375hz

  índice/componente  2048 – > 22050hz

Opa we arrived at the component 2048 which is the maximum frequency allowed by the Nyquist theorem.

That reminds you of something Fs * i / N ? It is the derived equation to know what is the corresponding frequency of a given index, whether to try ?

Fs = 44100
N = 4096
i= ?

let’s apply in the formula:

44100*1/4096 = 10.7666
44100*2/4096 = 21.5332
44100*3/4096 = 32.2998
44100*4/4096 = 43.0664

So imagine now that the peak of magnitude happened on the number index 90, then again using the formula 44100*90/4096 = 968.9941hz

I don’t know if you know, but the above method is not recommended at all in the use of tuners and frequency capture, the peak magnitude does not always make up the correct perception of a certain frequency this is due to the psychoacoustic phenomenon, but this is another subject, there are different frequency capture methods in the time domain and in the frequency domain.

Answering the doubts of the comments

Can you recommend me some book or online course to find out more on the subject. I want to delve into this subject of audio processing

Here in Brazil I do not know courses for sound engineering, outside there are reputable universities in this subject, the principle for audio manipulation I learned was in my computer engineering course, studying signal analysis in the field of digital processing, the electrical engineering course addresses the subject more fully, there are some courses in audio that I recommend on the internet, sound engineering principles and music-oriented signal processing get ready to understand math...

What is the equation for finding values in decibels from Y that was returned by the transform?

20 * log10((sqrt((real(FFT).*real(FFT))+(imag(FFT).*imag(FFT)))))

If x is the period, then for example, a vector of 4096 positions with Data captured at a sampling rate of 44100 will have on each position given for 0,092879818 seconds (4096/44100 =0.092879818 seconds) . So if I do 1/ 0.092879818 = 10.7666 Hz, it would be the frequency of each vector position being 10.7666 Hz a minor and 44097,536 Hz (10,766 * 4096) the highest frequency I can keep?

for a sampled signal on 44100hz and with number of points 4096 the lowest frequency is 10,7666hz and greater will be 22050hz

índice/componente  2048 – > 22050hz

because of Nyquist’s theorem

So if the order of resolution is approximately 10,766 Hz, it does not could distinguish a frequency of 450 Hz from a frequency of 445 Hz?

Exactly, there are ways to mitigate this problem by applying parabolic interpolation of neighboring indexes.

I don’t understand why you split 1/4096 and found this order of resolution. This resolution order is related to frequency or period?

Frequency and Period are equivalent, if you have the period of a signal you can know the frequency, if you have the frequency of a signal you can know the period...

With the vector in the time domain I could know which frequencies have smaller db and eliminate them from the vector to obtain greater precision in Frequency identification with the Fourier transform? Which options I have to improve frequency identification?

Unlikely to do this, but you can capture frequencies directly in the time domain, there are several algorithms to find pitch/frequency without the need to use the Fourier transform, some techniques, autocorrelation, ASDF, AMDF YUN i really like the AMDF wrote a code and left open source on tarsus, I’ve only done the basics and I haven’t implemented a few secrets in it, but you can use it as a basis to make yours, alias the experts and I also prefer time domain algorithms to find frequencies in monophonic audios. There are other types of algorithms in the frequency domain that are better than just finding the peak magnitude, look for subharmonic summation, Cepstrum and autocorrelação no domínio da frequência some of them have patents and no one demonstrates the mágica open source;

You said this isn’t the best way to get the frequency. What other ways could I use, besides the one that determines the frequency through magnitude. Because I actually saw a spectrogram of a flute and even playing a note, for example,440 Hz, the largest magnitude was the second harmonic , 880Hz. This happened with two notes that I don’t remember now. That is, really the frequency of the highest magnitude does not represent the frequency of the note

Use more intelligent algorithms than just pick up the peak magnitude, look for the algorithms indicated in the previous answer, the error you described of the flute is known as octave error, the algorithms mentioned above may also suffer from the same problem, a smart frequency detector can handle this, alias this type of problem is complicated to circumvent, it is so complicated that there are patents describing how to catch the pitch(frequency) correct, one way to do this is to observe if the highest peak has entire submullules with a certain equivalent magnitude of the highest peak, if a signal is periodic the period with the highest peak(P) will have another peak with an equivalent amplitude of 2*P...(keep this secret fondly rsrs)

  • Man, thank you so much for answering...I thought no one would answer...thanks really...helped too much. I realized that you have mastered the subject and I’m just getting started as you can notice...rsrs. You can recommend me some book or online course to learn more about the subject. I want to delve into this subject of audio processing.

  • What is the equation for finding the values in decibels from the initial Y that was returned by the transform?

  • If x is the period, then for example, a vector of 4096 positions with captured data at a sampling rate of 44100 will at each position have data for 0.092879818 seconds (4096/44100 =0.092879818 seconds) . So if I do 1/ 0.092879818 = 10.7666 Hz, it would be the frequency of each vector position being 10.7666 Hz the lowest and 44097.536 Hz (10.766 * 4096) the highest frequency I can save?

  • So if the order of resolution is approximately 10,766 Hz, it would not be able to distinguish a frequency of 450 Hz from a frequency of 445Hz?

  • I didn’t understand why you split 1/4096 and found this order of resolution. This order of resolution is relative to frequency or period?

  • With the vector in the time domain would I be able to know which frequencies have the lowest db and eliminate them from the vector to obtain greater precision in the frequency identification with the Fourier transform? What options do I have to improve frequency identification?

  • You said this isn’t the best way to get the frequency. What other modes I could use, besides the one that determines the frequency by magnitude. Because really I saw a spectrogram of a flute and even playing a note, for example,440 Hz, the greatest magnitude was the second harmonic , 880Hz. This happened with two notes that I don’t remember now. That is, really the frequency of the highest magnitude does not represent the frequency of the note.

  • @L.J tried to answer the questions in my answer gives a look there

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.