LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating my own FFT and THD VI

Dear all,

 

Thanks for taking the time to read my post.

 

Though I have published this in other post I will include this in the post for clarity.

 

I am using Labview 8 on Win XP CPU 3.4, 2GB RAM PC.

 

I am using a microcontroller PIC24 (on the Explorer 16 development board), which I have programmed to acquire an AC singal at a rate of about 4096 Hz. The PIC24 has a 10bit ADC and the acquire value is then padded to16bits in total (format: 0-0-0-0-0-0-d9-d8-d7-d6-d5-d4-d3-d2-d1-d0) as an unsigned int.

 

To make things a bit more clear, the PIC has a small, 4-bytes Hardware buffer and I have implemented a 2049-byte software buffer before that. I should point out that the PIC is sending its acquired data in uncontrolled chunks of data.

 

The serial settings for the PIC and my Labview program are 115200, 8 data bits, no parity, 1 stop bit.

 

In order to send the acquired value to my PCs serial port (Remember UART = 8-bits of data only) I divide the 16 bit word into MSB and LSB. I then send the MSB and LSB 8-bit value one after the other.

 

The format I use is:

ADC_High = 0-0-0-d9-d8-d7-d6-d5

ADC_LOW = 1-0-0-d4-d3-d2-d1-d0

 

After the VISA Read VI has read and outputted the data (in string format), I am removing the 3-MSB from both ADC_HIGH and ADC_LOW.

 

Once the 3-MSB have been removed, I concatenate the two strings (ADC_HIGH and ADC_LOW).

 

After that I type cast the concatenated string back to unsigned int and normalize the value.

 

Now for the question.

 

I added to the program a simple ‘FFT and THD VI’, that I had written previously. However the ‘Amplitude and Phase Spectrum VI’ does NOT work.

 

I am trying to investigate why this is, but any help would be much appreciated.

 

Would some one be as kind as to check the attached VI’s and give me some advice on what I might be doing wrong?

 

Regards

Alex

0 Kudos
Message 1 of 17
(6,144 Views)
Hi Alex( I believe we may have met in Cardiff!?)
 
Your THD-SAM.vi will not work as you are not feeding it with the correct datatype. You are feeding a scalar value ( you are not actually building an array in this way).
 
Your VI is written in a way that it expects an array of values representing the amplitude of your signal. The attached VI (v8.2.1) is a modified version of yours that is
 
working with a simulated 100 Hz sinusoid.  You may want to look into the built in LabVIEW THD functions as well.
 
Please let us know if that helped.
 
KostasB
 
NI Applications Engineering
 
p.s for those interested in this thread there is more history about it at
 
 
 
0 Kudos
Message 2 of 17
(6,112 Views)
Thanks for your reply kosta.
 
We did indeed meet in cardiff about a year ago.
 
Unfortunatelly I am unable to open the file you sent me, as I am running Labview 8.0.
 
Would it be much to ask for a print screen (or could you save the file in LV8.0).
 
Thanks
Alex
 
 
 
0 Kudos
Message 3 of 17
(6,107 Views)
There you go...let me know how it went.
 
KostasB
 
NI Applications Engineering


Message Edited by KostasB on 01-15-2008 10:43 AM
0 Kudos
Message 4 of 17
(6,100 Views)
There you go...let me know how it went.
 
KostasB
 
NI Applications Engineering
0 Kudos
Message 5 of 17
(6,100 Views)

Thanks for your reply Kosta.

I understood my mistake but I am having some problems ratifying it.

How would I go about creating an array with out knowing before hand the number of elements? I tried using a FOR loop but had no success.

Any ideas would be much appreciated.

 

Regards

Alex

 

0 Kudos
Message 6 of 17
(6,092 Views)

Have a look at the 'Building arrays.vi' in the shipping examples. In general, you can wire the data on the border of the loop and use auto-indexing .

The picture illustrates the creation of a 100x1 array.

Regards,

KostasB

NI Applications Engineering



Message Edited by KostasB on 01-15-2008 11:35 AM
0 Kudos
Message 7 of 17
(6,088 Views)

Thanks for your reply Kosta.

 

This is exactly what I did, as you can see in the attached VI.

 

However, I am not getting the excepted results. I do NOT know why this is.

I am trying to correct the problem, but any advice would be more the welcome.

 

Regards

Alex

0 Kudos
Message 8 of 17
(6,080 Views)
I've attached the VI's that should work the way you want. Take a look on how to build the array by using a shift register and the build array function.
 
Please note that I've created a second identical array on the borders of the while loop that will become available when the while loop stops executing.
 
There is excellent material that should help you get going at
 
 
Let us know how you get on,
 
KostasB
 
NI Applications Engineering
Download All
Message 9 of 17
(6,061 Views)

Thanks for your reply Kosta.

 

This is very close to what I was trying to do myself. It can be very frustrating when you know what you want to do but have difficulty doing it.

 

I will go through the content of the link you suggested looking at. Hopefully that will improve my LV skills some more.

 

I do however, have a few questions on the code.

 

I am under the impression that, once an FFT has been performed on 1024 points, those exact number of points need to be removed form the shift register. What seems to happen is the shift register get bigger and bigger and the program gets slower and slower as it tries to perform an FFT on an ever increasing number of points.

 

Also the ‘# elements in queue’ variable gets larger and larger as the program can not process all the data fast enough.

 

My question to you would be, how would I go about removing the 1024 (or say X) number of points, from the shift register once the FFT-THD VI has processed those specific number of points?

 

Please have a look at the attached VI. I have used Array Subset to remove 1024 point once the True Case has been triggered and the FFT VI has executed. However, now I am not getting any points in the shift register.

 

Any advice would be more than welcome.

 

Regards

Alex

0 Kudos
Message 10 of 17
(6,050 Views)