LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FFTW on LabView

Hi,

Perhaps i'm being thick. Array 6 in the LV code that you gave us displays it's contents to five decimal places (the first value in the array is 2.10988) and so do all the other arrays. Is that not what you want?

Phil

Message Edited by therealkilkenny on 02-01-2007 03:49 PM

0 Kudos
Message 11 of 23
(2,372 Views)
I don't think the FFT in LabVIEW and FFTW have that big precision difference.  You might want to make sure these things:
 
(1) The input data has the same precision.  The TPX and ZPD file used in the LabVIEW is 6 decimal.  Do you use the same files in the Python program.  Or you save the files from the Python program.
 
(2) Before the FFT, the signal is windowed.  Do you apply the same window in the Python program.  Note that the Scaled Time Window is not symmetric.  If we use W(i) indicate the window coefficients, W(0)=0, W(1) = W(339), W(2)=W(238), W(3)=W(337), ..... 
Message 12 of 23
(2,369 Views)
Sorry for not clarifyeing this point correctly. YES I do get the numbers up to 4 d.p but they are not correct. only the first 2 digits of the decimal point are correct and my answer changes on the third decimal point and onwards. I can make the values to be displayed up to 19 decimal places if I want to, and LabView does it, BUT only the first 2 digits of the decimal points are correct but the values from the 3rd decimal point and onwards changes i.e. its not correct. E.g. 2.1023689 and this means that the answer is correct only up to 2.10 whereas the rest of the numbers are not correct because what I should probably get is 2.1097658.....

To "Nann":

I'm not 100 % sure of what you mean with you 2nd point. I do not apply any window restriction of any sort to my data on LabView, but instead I only read the TXT files that contain the data and feed it to FFT. I'm not sure if the FFT that LabView uses applies any window to my data, and I also have no idea what window size it uses (if any). I'm also not aware Python doing this neither.  However if you know how I can apply or change this window size than please let me know so that I can try and see if I get the final answer to be closer to the correct ansers.

To make the life easier I have also attached the Python code that does these calculations, specially the FFTW. He also made some comments at the beggining of the code trying to explain something, which I can't quite undestand what the person wanted to say neither.

Message Edited by Q<UL on 02-01-2007 04:54 PM

0 Kudos
Message 13 of 23
(2,365 Views)

Q<UL wrote:
... I do not apply any window restriction of any sort to my data on LabView, but instead I only read the TXT files that contain the data and feed it to FFT.

    Looking at the code you posted, I am pretty sure you're really applying a window before the FFT. Maybe things change if you wouldn't. 😮

     

    (Of course it would be easier to see if the code were a bit cleaner. You have wires going in all direction! ;))

     

Message Edited by altenbach on 02-01-2007 05:10 PM

Message 14 of 23
(2,349 Views)
Also here (The "window" control is set to hanning by default, so that's what you would get unless you actively change it):
 

Message Edited by altenbach on 02-01-2007 05:59 PM

Message 15 of 23
(2,336 Views)
Sorry, you're right, I didn't look at the code and to be honest I have no idea what I was trying but I just wanted to get the right answer somehow. All the 6 Arrays shown on the Front Pannel belong to 3 types of calculations that I was trying. The "Array & Array 2" provide one way of getting FFT, "Array 3 & Array 4" provide another way of calculating FFT, which is the same with "Array 5 & Array 6".
I just changed the Window's to different types to see if I get a different result but no luck again. My results range between 2.10 and 2.11, whereas they should be between 2.11 ato 2.12, with ofcourse more precission, but I should have the number 2.12 occuring just as much as I have 2.11 occuring at the moment.
0 Kudos
Message 16 of 23
(2,334 Views)
What kind of windows do you apply in the fftw implementation?
 
How about "window=none"? 😉
0 Kudos
Message 17 of 23
(2,329 Views)
Looked quickly at the Python script, and it looks like the SetY() function is applying a cosine sqsuared weighting.  YAV is the variable that is passed to the FFTW function shortly after the SetY function returns.
for i in range(n):
A = math.cos(i*math.pi/n) # Unity weighting on first point (ZPD)
Wt = A*A
YW.append(Wt)
YAV.append((YRAW[i] - Ymean)*Wt)
I wasn't overly careful in following the function calls, but it looks like this is the culprit.  Because the python script is giving the results you expect I would suggest implementing this weighting function exactly in LabVIEW, then call the FFT without any additional windowing.

There will be some numerical differences between the LabVIEW FFT implementation and FFTW, if only because the order of the operations and algorithm may be different.  However, the differences should not be in the first few significant digits but much farther out, and I would be surprised if the different FFT results were the cause of your problem.  If you want additional verification write a simple Python script to generate a sequence of numbers, and compare the FFTW results to the same LabVIEW FFT of the identical sequence.  Doing this should allow you to eliminate the FFT as the probable source of your problem, or not, in which case please do post your results so I can investigate further. Smiley Happy

-Jim

Message 18 of 23
(2,301 Views)
Sorry Jim for my late reply, but based on this weighting function that you've spotted on the script the only thing that I can derive is:

cos2(...) ;   The "2" means squared. But I can't see whats inside the bracket. What I get from the results that I read is shown on the attachment picture. Now, you can see that there are sidelobs around the maximum and minimum peaks, and my understanding right now is that he is trying to get rid of these sidelobs by applying this "Cosine squared weighting". But I don't understand what is inside those brackets.
0 Kudos
Message 19 of 23
(2,289 Views)
range(n) means [0,1,2,...,n-1], so i iterates from 0 to n-1
A will take on values: cos(1*pi/n, cos(2*pi/n), cos(3*pi/n), ..., cos( (n-1)*pi/n
and Wt will be A*A
YW is an array containing each value of Wt.

I have attached a simple VI that just implements the following lines of the python script:
Ymean = sum(YRAW)/len(YRAW)

n = len(YRAW)
YW=[]; YAV = []

# Use Cos-squared weighting.
for i in range(n):
A = math.cos(i*math.pi/n) # Unity weighting on first point (ZPD)
Wt = A*A
YW.append(Wt)
YAV.append((YRAW[i] - Ymean)*Wt)

I didn't try to figure out the context of this weighting wrt the rest of the script; there may be some buffer manipulation (shift or rotate) that changes things.  It seems odd to me to window with a cosine this way.  The first and last points have the greatest weights, while the middle of YRAW is weighted the least.  Normally the weighting is done as 1-cos(), so the endpoints are weighted least, with the middle of the buffer weighted the most.

Translating from one language to another can be tedious and problematic.  Through much pain (banging my head on any available flat surface Smiley Mad), tribulation, and wasted time I have learned to break off manageable and verifiable pieces of the translation b y mapping function calls directly to VI calls.  Your python script is already nicely broken into function calls; debugging the equivalent G code might be easier if you duplicated the functions as subVIs.  Just a thought.

Anyway, maybe this will help get you closer.Smiley Happy

-Jim
0 Kudos
Message 20 of 23
(2,258 Views)