LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need help with convolution sum in Labview

Solved!
Go to solution

Hi everyone,

I’m working on calculating the convolution sum in the frequency domain for two discrete-time systems. My approach so far has been to shift one signal element by element while keeping the other fixed. At each iteration, I multiply the two signals and compute the summation of all elements in the resulting array to get each point p(i)p(i). However, the results are not as expected.

Does anyone know the proper algorithm for this or what I might be doing wrong? Any advice would be greatly appreciated!

Thanks in advance!

0 Kudos
Message 1 of 21
(183 Views)

 

LabVIEW has 1D and 2D convolution built-in. That's probably all you need. (unless you only have "LabVIEW base").

 

Can you attach a simple VI with some typical data so we can see what you are doing? We don't know what results you "expect", so it could even be that your expectations are wrong.

 

0 Kudos
Message 2 of 21
(147 Views)

So I'm trying to do a convolution of two Fourier Transforms, one for Voltage and one for current. I have the fourier transform of both and I need to convolute them in order to obtain the power.

But I don't get the correct result.

In the attached picture is how I'm trying to do it. 

gaiab03_0-1732815765881.png

gaiab03_1-1732815783070.png

I think there might be a problem due to the fact that Fourier Transform are complex number. 

I don't know how to handle it, should I convolute the real part and imaginary part separately (or with the 2-D convolution) and then reconstruct the power vector?

0 Kudos
Message 3 of 21
(135 Views)

For a circular convolution, you would just multiply the two complex transforms and transform back

 

As a first step, you need to do some basic LabVIEW tutorials and learn about the principles of dataflow. You have two independent code segments that run in parallel and the one on top runs exactly once while the bottom is a while loop masquerading as a FOR loop because the number of iterations are known before the loop even starts. I assume you think that number of iterations should depend on the size of the input arrays, right? So why is it a constant? There is no way to tell in what order the locals are read or written.

 

In LabVIEW, "the wire is the variable" and determines execution order. You should not need any local variables or sequence structures at all! (terminals are just for communicating with the user, they should not be abused for data shuffling).

 

Of course we cannot really run or debug pictures, so please attach your actual VI and some typical data. Make sure to "save for previous" (2020 or below) so more have a change to inspect.

Message 4 of 21
(128 Views)

So Basically this is what I have to do: 

Develop a virtual instrument that

 

  • simulate a voltage and a current: they are two periodic signals whose harmonic components can be chosen in the front panel throught a control. 
  • evaluate the instantaneoud power and the power spectrum according to both the short and long algorithms seen at lesson. 

 

The following graphs must be shown: 

 

  • acquired voltage and currents, 
  • spectrum of voltage and current, 
  • spectrum of power coming from each algorithm, 
  • instantaneous power coming from each algorithm. 
     
    everything works fine except for the power calculated with the long alghoritm that convolutes the tension and current in the fourier domain (I called the result connv). I implemented it on Matlab and it works fine with this code:
    clear all
    a=zeros(200, 1);
    a(2,1)=-150i;
    a(4,1)=-100i;
    a(6,1)=-50i;
    a(102,1)=-150i;
    a(104,1)=-100i;
    a(106,1)=-50i;
    a(100,1)=150i;
    a(98,1)=100i;
    a(96,1)=50i;
    a(200,1)=150i;
    a(198,1)=100i;
    a(196,1)=50i;
    b=zeros(200, 1);
    b(2,1)=-250i;
    b(4,1)=-100i;
    b(102,1)=-250i;
    b(104,1)=-100i;
    b(100,1)=250i;
    b(98,1)=100i;
    b(200,1)=250i;
    b(198,1)=100i;
    c=zeros(200, 1);
    for i=1:1:200
    l=200;
    for k=1:1:200
    if i-k>0
    c(i)=c(i)+a(k)*b(i-k);
    else
    c(i)=c(i)+a(k)*b(l);
    l=l-1;
    end
    end
    end

     
    % Plot the histogram of abs(c)
    figure(1);
    bar(1:200, abs(c)); % Plot the absolute values of c
    xlabel('Array Indexes');
    ylabel('Amplitude');
    title('Histogram of abs(c)');
    grid on;
    I tried to implement the same alghoritm in labview but it does not work. I need a graph like the one attached.
    gaiab03_2-1732894028357.png

     

    VI is attached, and datas:
    for tension fundamental freq 50, harmonics 1,3. Amplitude 5,2
    for current fundamental freq 50, harmonics 1,3, 5. Amplitude 3,2,1
    sampling freq 5000, mtot 100
     
0 Kudos
Message 5 of 21
(92 Views)

@altenbach wrote:

Make sure to "save for previous" (2020 or below) so more have a change to inspect.


I cannot look at your code at the moment because whatever you attached is in LabVIEW 2023. Sorry.

0 Kudos
Message 6 of 21
(84 Views)
0 Kudos
Message 7 of 21
(82 Views)

Your code suffers severely from localitis and sequenceitis, typically indicating that you are a seasoned text programmer with very little LabVIEW experience. I am sure it could be done right with flat code that fits on a postcard. 😄

 

Did you notice the red coercion dots? Wiring a complex local variable to an EXT indicator seem unusual. Your M and N should probably be blue (I32), right?

 

Can you make sure that all controls contain typical data? Currently all inputs are zero or empty arrays, which is not useful for testing. I assume this is a subVI, but there are no connectors assigned, so how exactly are you testing this??? The problem with local variable overuse is also that it blurs the difference between control (data source) and indicator (data sink). It is very difficult to tell what are inputs or outputs.

 

Can you assign reasonable values to all controls, select all controls and do a "edit...make selected values default". Save under a new name and attach again after saving for previous.

0 Kudos
Message 8 of 21
(75 Views)

Add all control. I'm so sorry for all these misunderstandings, it is my first LabView project, and I'm getting crazy trying to figure out everything from scratch. 

I also think the problem is in the ext variable but I'm really clueless about what to do next.

All adjustaments and feedbacks are welcome

0 Kudos
Message 9 of 21
(70 Views)

Controls are still all zeroes or empty arrays.

 

altenbach_0-1732902519171.png

 

0 Kudos
Message 10 of 21
(68 Views)