If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
DLL Stream FFT (Finally some progress)
16 posts
• Page 1 of 2 • 1, 2
DLL Stream FFT (Finally some progress)
I was reading excellent article by KG about FFT and I decided to recreate everything in green so I can better understand what is going on inside FFT algorithm. My goal is to make DLL stream FFT, but first I must done it using green.
What is not clear to me is this part of the article:
So, I don't know how to get magnitude and phase and how actually to perform FFT on all frequencies...
Here is my progress so far...
What is not clear to me is this part of the article:
If we do complex math we can multiply by sine and cosine in a single step. Result will be a complex number – real part will be the magnitude of cosine part and imaginary part will be the magnitude of sine part. We can still calculate the magnitude and phase in very same way. If we do this for every harmonic in the spectrum and plot the complex outputs into graph (3D graph – x = frequency y=real z=imaginary) we have in fact preformed Fourier Transform and we now have the frequency-domain representation of our signal.
So, I don't know how to get magnitude and phase and how actually to perform FFT on all frequencies...
Here is my progress so far...
- Attachments
-
- FFT in Green.fsm
- (3.25 KiB) Downloaded 950 times
Last edited by Youlean on Fri Jan 01, 2016 10:58 pm, edited 2 times in total.
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
Re: Help with green FFT
Tronic wrote:this post can help you to port to dll?
see the DWB ruby code
viewtopic.php?f=4&t=1510&hilit=fft#p6433
The problem is that I don't understand that much Ruby code, but if you can explain me some parts I could probably do it...
Can you comment the code so I can better understand it? I will add question mark for what is not clear to me...
- Code: Select all
def fft doinverse = true
src = self
# raise ArgumentError.new "Expected array input but was '#{src.class}'" unless src.kind_of? Array
n = src.length
nlog2 = Math.log( n ) / Math.log( 2 )
raise ArgumentError.new "Input array size must be a power of two but was '#{n}'" unless nlog2.floor - nlog2 == 0.0
n2 = n / 2
phi = Math::PI / n2
if doinverse
phi = -phi
else
src.collect!{|c| c /= n.to_f}
end
# build a sine/cosine table
wt = Array.new n2
wt.each_index { |i| wt[i] = Complex(Math.cos(i * phi), Math.sin(i * phi)) } ???Is this building 2 dimensional array?
# bit reordering ?? What is this doing?
n1 = n - 1
j = 0
1.upto(n1) do |i|
m = n2
while j >= m
j -= m
m /= 2
end
j += m
src[i],src[j] = src[j],src[i] if j > i
end
# 1d(N) Ueberlagerungen ???
mm = 1
begin
m = mm
mm *= 2
0.upto(m - 1) do |k|
w = wt[ k * n2 ]
k.step(n1, mm) do |i|
j = i + m
src[j] = src[i] - (temp = w * src[j])
src[i] += temp
end
end
n2 /= 2
end while mm != n
src
end
end
//usage
real = []
imag = []
@in.fft(false).each {|i| real.push i.real; imag.push i.imag}
output 0, real; output 1, imag
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
Re: Help with green FFT
???Is this building 2 dimensional array?
yes, you can manage it like an 2D array, but you have to think it as an associative array "real:part + immaginary:part"
and you can use the <complex> stdlib class in c++
?? What is this doing?
butterfly algorithm....
http://www.katjaas.nl/bitreversal/bitreversal.html
Ueberlagerungen ???
this calculate the overlapped pieces for the windows
yes, you can manage it like an 2D array, but you have to think it as an associative array "real:part + immaginary:part"
and you can use the <complex> stdlib class in c++
?? What is this doing?
butterfly algorithm....
http://www.katjaas.nl/bitreversal/bitreversal.html
Ueberlagerungen ???
this calculate the overlapped pieces for the windows
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Help with green FFT
Thank you for all great information.
- Robertocrarswell
- Posts: 2
- Joined: Tue Dec 29, 2015 6:45 am
Re: Help with green FFT
Ok, thanks. Sorry for late response..
I still dont understand what this peace of code is doing.
Is this building sine and cosine of whole array size (one sine cycle in, for example 1024 array) and then getting their complex number (2 arrays are added to get one complex number) and then storing that numbers on each index in wave table array?
wt.each_index { |i| wt[i] = Complex(Math.cos(i * phi), Math.sin(i * phi))
I still dont understand what this peace of code is doing.
Is this building sine and cosine of whole array size (one sine cycle in, for example 1024 array) and then getting their complex number (2 arrays are added to get one complex number) and then storing that numbers on each index in wave table array?
wt.each_index { |i| wt[i] = Complex(Math.cos(i * phi), Math.sin(i * phi))
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
Re: Help with green FFT
Youlean wrote:wt.each_index { |i| wt[i] = Complex(Math.cos(i * phi), Math.sin(i * phi))
Complex is a number construct in Ruby. It looks like this: a+bi, for example 0.3+0i for 0.3
If you call Complex with two parameters, the first one will be the real part and the second the imaginary part. So this array will have i entries with each entry being a complex number.
If you later need to split the complex into its parts, you just call .real and .imag
- Code: Select all
a = Complex(1, 0.53)
b = a.real # = 1
c = a.imag # = 0.53
In the code this is done at the end
- Code: Select all
//usage
real = []
imag = []
@in.fft(false).each {|i| real.push i.real; imag.push i.imag}
output 0, real; output 1, imag
this is going through the array and splitting each complex into real and imag, adding them to their own array.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Help with green FFT
Ok, I think that I start to getting it... Can someone put this ruby fft into flowstone ruby so I can debug my code in dll more easily?
I think that I was someware ruby fft module but can not find it...
I think that I was someware ruby fft module but can not find it...
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
Re: Help with green FFT
Not sure how far you got, Youlean, but if you are trying to understand FFT and ruby does not (yet) feel comfortable then I'd recommend Numerical Recipes. The second edition is free and chapter 12 has it all on FFT, including C-code (or Fortran, if you prefer ).
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: Help with green FFT
martinvicanek wrote:Not sure how far you got, Youlean, but if you are trying to understand FFT and ruby does not (yet) feel comfortable then I'd recommend Numerical Recipes. The second edition is free and chapter 12 has it all on FFT, including C-code (or Fortran, if you prefer ).
Well, I made DFT working so far. Thanks for the tip. I found many C algorithms but I can get it work.
I have tried this algorithms for example.
The strange thing is that DFT version works OK, but FFT not, it just return me values like they are on input and this is really strange because I tried 3 other FFT algorithms that are doing same thing...
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
16 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 43 guests