Download the free trial version
Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.
Desktop Recorder
03-16-2010, 11:58 AM
Basic4ppc Expert
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Quote:
EDIT : - ToRealAmplitude is not a good name because of "Real." I thought I might call it ToAmplitudes, note the plural, but is that too close to the existing ToAmplitude method name? I will also add the complementary ToPhases method.
Perhaps:
ToAmplitudePhase
ToAmplitude
ToPhase
Best regads.
__________________
Klaus
Switzerland
03-16-2010, 12:03 PM
Basic4ppc Expert
Quote:
Originally Posted by
klaus
- send, in the data() array to the FFT object, only the real values- the imaginary 0 samples are generated inernally in the FFT dll
That would waste some time. After you DIM an array .NET fills it with zeros so on a new array it is only necessary to fill in the Real values.
Quote:
- get back only the first half of the real and imaginary samples, only the useful ones
I've already suggested that in the post above but I need a better name or to rename some existing methods, any suggestions?
Quote:
or eventually use a 'FFT algorithm specialized for real and/or symmetric data' with the same inputs and outputs.
I'll leave that to someone who is more confident with the maths than I am.
Quote:
I will make some improvements.
I'll wait till you have done that
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
03-16-2010, 12:12 PM
Basic4ppc Expert
Quote:
Originally Posted by
klaus
Perhaps:
ToAmplitudePhase
ToAmplitude
ToPhase
I've already got ToAmplitude and ToPhase. How about GetAmplitute and GetPhase or shall I do a complete rename of the existing methods? What did you intend ToAmplitudePhase to do?
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
03-16-2010, 12:45 PM
Junior Member
Join Date: Jan 2009
Posts: 23
Allow me to summarize what I understood from these detailled posts, related to my example:
Filling the array only with 4096 real bytes from my sound sample will work mathematically, giving 100% correct results, but could take more time. Is that correct to assume ?
I understand the .NET mechanism that fills an array at declaration time with zeros, and see the benefits. I also understand now how the fft library is able to handle an input with only real values anyway, as it seems to generate the zero (imag) values itself internally.
BTW, I tried both methods, and besides the probable speed difference, the results looked good every time.
In my real life app, I only look for frequencies between 33 and 166 Hertz, being 1000 to 5000 RPM "headspeed" for a 2 bladed R/C helicopter. Simply 33*60/2 and 166*60/2. And until now, in this small, lower part of the spektrum, i only encountered this 1 frequency, together with 1 harmonic with exactly half the frequency, but less than half in amplitude. So my code can easily make the difference between those two, leaving no room for error.
I visualised this by means of a graph indeed, to be able to control this.
The user is of course responsible of making a recording with no other sound sources present. All the other frequencies generated by a R/C heli are much higher, being the 2-3 times faster turning tail blades, or the even higher RPMs of the electric motor, and all harmonics I found until now.
Last edited by redbird : 03-16-2010 at 12:48 PM .
03-16-2010, 02:18 PM
Basic4ppc Expert
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Hi Andrew,
I'm coming back on my suggestion 1) transfering in the Fft.Transform function only the real data.
I had a look at your library with SharpDevelop and saw that the real and imag samples could relatively easy be treated separately.
- real data in the input, half the length than before
- so, n = data.length and no more n = data.length/2
- generate an internal array for the imag data samples
- everywhere you have data(i) or data(j) is the real input data array realdata(i)
- everywhere you have data(i+1) or data(j+1) is the internal imag data array imagdata(i)
- for the return copy the first half of the imag samples into the second half of the data array.
Just to illustrate
Code:
<font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font></font></font></font><font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j </font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >+ </font></font></font></font><font size= " 2 " ><font color= " #00008b " ><font size= " 2 " ><font color= " #00008b " > 1 </font></font></font></font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font></font></font></font><font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i </font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >+ </font></font></font></font><font size= " 2 " ><font color= " #00008b " ><font size= " 2 " ><font color= " #00008b " > 1 </font></font></font></font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i </font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >+ </font></font></font></font><font size= " 2 " ><font color= " #00008b " ><font size= " 2 " ><font color= " #00008b " > 1 </font></font></font></font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font></font></font>
would become
Code:
real<font size= " 2 " >data</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font><font color= " black " >real</font></font></font></font><font size= " 2 " ><font color= " black " >da</font>ta</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imagdata</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font><font color= " black " >imag</font></font></font></font><font size= " 2 " ><font color= " black " >d</font>ata</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >realdata</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imagdata</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font></font></font>
Could you please have a look at this.
If this is could be done, then we do no more need two methods for Amplitude and Phase.
With
ToAmplitudePhase I was thinking of a single method for getting both arrays, but two seperate functions are OK for me.
Best regards.
__________________
Klaus
Switzerland
03-16-2010, 02:34 PM
Basic4ppc Expert
It's not quite that simple as the loop arithmetic needs altering together with some other indexing stuff but I'll have a think about restructuring the library as it has grown a bit like Topsy.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
03-16-2010, 03:05 PM
Basic4ppc Expert
Try this, it's probably buggy as I haven't played with it. To keep things simple and retain the full inverse transform capability I didn't generate imaginary internal values. Dimming a new array initialised to zeroes is just as cheap in Basic4pc code as in C#.
void Transform(double[] real, double[]imag)
void Inverse(double[] real, double[] imag)
double[] CopyArray(double[] array)
double[] ToAmplitude(double[] real, double[] imag, double scale)
double[] ToPhase(double[] real, double[] imag)
ToAmpAndPhase(double[] real, double[] imag, double scale) ' half and half
double[] ToReal(double[] amplitude, double[] phase, double scale)
double[] ToImaginary(double[] amplitude, double[] phase, double scale)
EDIT :- It doesn't work. I don't understand the indexing (k) in the bitreverse method so can't get it right for separate Real and Image arrays and theres a similar problem (b) in the actual transform. I'm going back to the original algorithm but will make it accept and return separate arrays.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Last edited by agraham : 03-16-2010 at 05:42 PM .
03-16-2010, 06:47 PM
Basic4ppc Expert
I'm beginning to wish I hadn't started this separate array stuff
Try this version with the same methods listed above.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
03-16-2010, 06:51 PM
Basic4ppc Expert
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Hi Andrew,
I just cam back home, and looked at the library.
What version is FFTV1.2 ?
The one before your edit ?
I had a look at the FFT.cs file and found that in lines 65-68
Code:
<font size= " 2 " >real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font></font></font></font><font size= " 2 " >real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font></font></font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font></font></font>
should be
Code:
<font size= " 2 " >real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font></font></font></font><font size= " 2 " >real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >j</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] = </font></font></font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] - </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " ><font color= " red " >real</font></font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_real</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font> </font></font><font size= " 2 " >imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >[</font></font></font></font><font size= " 2 " >i</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >] += </font></font></font></font><font size= " 2 " >wd_imag</font><font size= " 2 " ><font color= " #006400 " ><font size= " 2 " ><font color= " #006400 " >;</font></font></font></font>
This evening I won't be at home.
Best regards.
__________________
Klaus
Switzerland
03-16-2010, 06:59 PM
Basic4ppc Expert
Quote:
Originally Posted by
klaus
What version is FFTV1.2 ?
V1.1 takes a single data() array
V1.2 attempted modified algorithm to take real() and imag() arrays - FAILURE for at least two reasons.
V1.3 original alogorithm wrapped to look like V1.2
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT. The time now is 01:18 AM .