Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

Desktop Recorder

Reply
 
LinkBack Thread Tools Display Modes
  #31 (permalink)  
Old 03-15-2010, 06:47 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
I've no idea why the IDE thinks that FFT is a keyword, it doesn't highlight other library objects, although I have suggested to Erel that it should but he wasn't keen on the idea.
My impression is that object names get highlighted if their names are the same as the library but not otherwise. Which seems strange to me; does a library name have any relevance in code?

Mike.
Reply With Quote
  #32 (permalink)  
Old 03-15-2010, 07:11 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

I'd forgotten that the latest IDE highlights library Class (Object) names. I think it was added because the Control keyword is superseded by a new syntax that uses an objects or controls' Class name and this in turn lets Intellisense work as the IDE now knows the type of the object so a library name is now relevant within code.

Control ("Form" & i, Form).Circle(...) 'old syntax
Form ("Form"& i).Circle (...) 'new syntax
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #33 (permalink)  
Old 03-15-2010, 07:44 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Andrew,
Thank's for uploading the last version of the FFT library.

I tried the new functions and saw an error with the ToPhase function wich gives wrong results.
The Tan function should be the ATan2 function
with 0 < angle < PI when y is positive
and 0 <angle < -PI when y is negative

When, in the attached, new version of the test program you :
- click on '1 Sine damped', pure damped sine
- click on the 'Calc FFT' button
- click on the 'A / P' button

You get the result in the first image, but it should be like the 2nd image.
The 2nd real sample is 1.364... and the imag sample is -0.00035... with x positive and y negative the angle should be negative.

Shouldn't we open a new thread for the FFT library ?

Best regards.
Attached Images
File Type: jpg FFTPhase1Wrong.jpg (20.3 KB, 1 views)
File Type: jpg FFTPhaseOK.jpg (19.5 KB, 3 views)
__________________
Klaus
Switzerland
Reply With Quote
  #34 (permalink)  
Old 03-15-2010, 08:02 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

You missed attaching the attachment

Quote:
Originally Posted by klaus View Post
The Tan function should be the ATan2 function
It does use the .NET Math.Atan2 function. It is the same Atan2 function as Basic4ppc uses so the problem must be elsewhere.

ph[i] = Math.Atan2(imag[i], real[i]) * DegPerRad;

In the docs Atan2 is specified as the return value is the angle in the Cartesian plane formed by the x-axis, and a vector starting from the origin, (0,0), and terminating at the point, (x,y). It is an angle, θ, measured in radians, such that -π≤θ≤π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. Observe the following:

For (x, y) in quadrant 1, 0 < θ < π/2.

For (x, y) in quadrant 2, π/2 < θ≤π.

For (x, y) in quadrant 3, -π < θ < -π/2.

For (x, y) in quadrant 4, -π/2 < θ < 0.


Quote:
Shouldn't we open a new thread for the FFT library ?
I was waiting till we were happy with it and then I was going to do a help before starting a new library thread for it.


EDIT:- Commenting out 'FFTPhase(i)=ATan2(FFTImag(i),FFTReal(i))*RadDeg in the For loop in CalcFFT in your previous example and inserting
FFTPhase() = Fft.ToPhase(FFTReal(), FFTImag()) after the Next looks OK for me. Did you get the order of the parameters of ToPhase correct? I see your graph if I reverse them.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 03-15-2010 at 08:19 PM.
Reply With Quote
  #35 (permalink)  
Old 03-15-2010, 08:43 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Sorry, my mistake !

I had inverted the order of Real and Imag in the ToAmplitude function.

When doing it right it works OK !
Unfortunately, as often the most obvious mistakes are overseen.

Attached the last test program version.

Best regards.
Attached Files
File Type: sbp FFTdemoKC1.sbp (10.4 KB, 7 views)
__________________
Klaus
Switzerland

Last edited by klaus : 03-15-2010 at 08:47 PM.
Reply With Quote
  #36 (permalink)  
Old 03-15-2010, 10:30 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

You are a bit off form today Klaus .

You have got

FFTAmpl()=Fft.ToAmplitude(FFTReal(),FFTImag(),1)
FFTPhase()=Fft.ToPhase(FFTReal(),FFTImag())

inside your For loop which is of course a "bad thing". Not like you to miss something like that


I'll put together a help and library archive and post it in a day or so. Is it OK if I use your program as the demo app for the library?
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #37 (permalink)  
Old 03-15-2010, 11:19 PM
Junior Member
 
Join Date: Jan 2009
Posts: 23
Default

Klaus and Agraham,

I admire your work and knowledge a lot, but I'm afraid I don't understand all of it anymore.
Could you please confirm this rather simple question for me, as I'm starting to doubt now:

I take 4096 subsequent bytes of a recorded, uncompressed 8 bit sampled sound file, being timed amplitudes in fact, and i put these values (varying from 0 to 256) in the array data(), without adding any zeros for imag numbers. A plain and simple real value array. And after doing the fft.transform(rawdata()), do I get the correct (2 X 2048) numbers back in the array, being a real value, an imag value, a real value, an imag value, and so on ? Klaus his words about his results that seemed close without adding zero values confused me a bit, I probably didn't understand completely.

Note: I rely on this array to calculate the magnitudes by looking to the absolute values (square root of (real^2) + (imag^2)). And the largest magnitude in the frequency range I'm looking for allows me to determine the unknown frequency at last, knowing the sample rate of 11025 samples/second in my case.

Last edited by redbird : 03-15-2010 at 11:27 PM.
Reply With Quote
  #38 (permalink)  
Old 03-16-2010, 12:18 AM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 269
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
... as the IDE now knows the type of the object so a library name is now relevant within code.
Yes, and I'm most impressed with that, as at first I thought it was only for the included and packaged libraries - but it does it for any library (tested with many of yours)
Reply With Quote
  #39 (permalink)  
Old 03-16-2010, 11:25 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by redbird View Post
Could you please confirm this rather simple question for me
You need to take your 4096 samples and put them in a 8192 long array, say data(), at even numbered (Real) positions setting the odd (Imaginary) positions to 0.

Do the FFT and data() will now contain the Cosine amplitudes at even (Real) positions and Sine amplitudes at odd (Imaginary) positions.

Use FFT.Split to separate data() into two 4096 long arrays containing the Real and Imaginary values.

Use FFT.ToAmplitude, the scale parameter doesn't matter for you - use 1. This returns a new array 4096 long which contains the amplitudes. Use the first 2048 values of this to look for your maximum.

Is it always valid to assume that the maximum amplitude frequency is the one you are interested in? Perhaps a bit of visualisation for the user to confirm or select the chosen frequency might be a useful feature.

As it is mainly the Real amplitudes that are of interest I will add a ToRealAmplitude method that will extract those, in your case 2048 values, directly from the data() array so avoiding the Split step.

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.
__________________
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 11:49 AM.
Reply With Quote
  #40 (permalink)  
Old 03-16-2010, 11:55 AM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Andrew and redbird,

I did some 'brainstorming' last night, luckily not all night.

Coming back to the FFT priciple:
- from the mathematical point of view the, the imaginary samples are necessary in the FFT algorithm in agraham's library .
- from the user's point of view, almost all calculations are done with physical signals without any imaginary component.

In redbirds example:
- today he has 4096 real samples from his physical signal
- he needs to create an array with 4096 zeros for the imaginary part (with no use other than to satisfy the mathematic algorithm)
- he gets back 4096 real and 4096 imaginary frequency samples
- half of them are of no use because the second half of the samples are the conjugate values of the first half (first half real + imag second half real - imag ) the real values are the same the imaginary values are oppsite (sign changed)

My suggestions:
1)
- send, in the data() array to the FFT object, only the real values
- the imaginary 0 samples are generated inernally in the FFT dll
- get back only the first half of the real and imaginary samples, only the useful ones

2) or eventually use a 'FFT algorithm specialized for real and/or symmetric data' with the same inputs and outputs.
Fast Fourier transform - Wikipedia, the free encyclopedia

In redbirds example.
sending 4096 samples instead of 8192
getting back two sets of 2048 samples instead of two sets of 4096 samples

That's what I was used to, and that's what made my confusion at the beginning.
And I am shure that it will avoid confusions for others in the future.

I tested the library at the beginning with very low frequencies, this means that the succesive samples had relatively small differences. This was seen by the library as having the real and imaginary samples similar. So the results looked almosed coherent.
But with higher frequencies the results are wrong.

In frequency analisys the user is mostly interested in the highest peaks of the amplitude signal. Some analizers have a function returning a list of the frequencies higher than a certain threshold.

@agraham
Could you please take in consideration my suggestions, at least the 1st one.
For shure you can use my test program as the demo program !
I will make some improvements:
- add some more possibilities
- make a better more userfriendly interface
- add some help for the user

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
player-recorder derez Share Your Creations 5 11-23-2009 08:59 PM
Recorder That Emails the File craigisaacs Open Source Projects 9 07-15-2009 07:22 PM
Question about Desktop Recorder for Erel Pachuquin Questions (Windows Mobile) 3 07-10-2009 08:37 AM
Recorder Erel Additional Libraries 11 12-23-2008 05:36 PM
Calendar Recorder Rioven Share Your Creations 5 10-21-2007 07:55 AM


All times are GMT. The time now is 01:16 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0