Saturday, January 25, 2020

signal analysis - Is there any algorithm to decompose a wave into a set of given frequencies?


I heard about Fast Fourier Transform can decompose any waves.


But it seems like it was hitting for "all frequencies", namely, n HAVE TO be from 0 to N-1!


What if I want to decompose the wave into the frequencies I want!?


Such as, for example, 5Hz, 14Hz, 37Hz, 42Hz, 59Hz, etc.!?



Is there any algorithm that could do the job!?


PS. My understanding of FFT is from Google, and the degree of understanding is VERY limited! So PLEASE forgive me for my lack of knowledge and any stupid comments!



Answer



If you have a mixed signal of various known frequencies, the Goertzel answer mentioned above will you correct values only if you have chosen a frame size which has a whole number of cycles for each frequency. Otherwise, if the frequencies are spread far enough apart you will get an approximation. In general, you need to work harder than that to get the correct values.


To simplify, this example will use two of your frequencies, and I'll keep it real (as in not complex).


First you have to construct a cosine (C) and sine (S) signal (vector) for each frequency the length of your frame. Then you want to find the best fit solution to:


x=a5C5+b5S5+a14C14+b14S14


Where x is your signal as a vector. The Cs and Ss are called basis vectors. Dot your signal with each of them:


C5x=a5C5C5+b5C5S5+a14C5C14+b14C5S14S5x=a5S5C5+b5S5S5+a14S5C14+b14S5S14C14x=a5C14C5+b5C14S5+a14C14C14+b14C14S14S14x=a5S14C5+b5S14S5+a14S14C14+b14S14S14


These equations can be put into convenient matrix form:



[C5xS5xC14xS14x]=[C5C5C5S5C5C14C5S14S5C5S5S5S5C14S5S14C14C5C14S5C14C14C14S14S14C5S14S5S14C14S14S14][a5b5a14b14]


Then it is simply a matter of multiplying both sides with the inverse of the square matrix:


[a5b5a14b14]=[C5C5C5S5C5C14C5S14S5C5S5S5S5C14S5S14C14C5C14S5C14C14C14S14S14C5S14S5S14C14S14S14]1[C5xS5xC14xS14x]


So, for each frequency you have an a and b value. Your 5Hz component will be a5C5+b5S5.


You can use the following to convert that into a phase and amplitude.


Acos(ωt+ϕ)=Acos(ωt)cos(ϕ)Asin(ωt)sin(ϕ)


From there, match:


a=Acos(ϕ)

b=Asin(ϕ)


Which leads to:


A=a2+b2



ϕ=atan2(b,a)


This is how a DFT actually works. When you select basis vectors that are a whole number of cycles, the square matrix turns out to be a multiple of the identity matrix and thus the inverse is trivial.


The Goertzel gives you a method of calculating Cnx and Snx on the fly.


No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...