LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lev-Mar non-linear fit problem

Hi Lynn,

 

Thank you for responding.

 

This is just an little more detailed overview of my project once again... 

 

1) I have 6 photodiodes which gives me 12 time datas from a laser illumination reflected from an oscillating mirror...Through a DAQ i get these datas into my GUI. (x-axis)

 

2) These photodiodes are arranged on a PCB and each have a particular position by which they are seperated. So now I have the y axis which is my position(amplitude) information.

 

3) I need to measue the amplitude at the resonant frequency of my mirror. Since I only have few uneven samples from the photo diode arrangement , I was hoping to fit a sine series fit (this gives me the harmonic coefficients aswell) and find the amplitude.

 

my equation form :  "y = a1*sin(2*3.14*f*x+c1)+a2*sin(2*2*3.14*f*x+c2)+a3*sin(3*2*3.14*f*x+c1)+a4*sin(4*3.14*f*x+c4)+a5*sin(5*3.14*f*x+c5) "

 

4)  Since I already know  the resonant frequency of my mirror i want to control it from the front panel itself and so basically i should have two unknown coeffecients for one sine term i.e the amplitude and phase. 
I have managed to import the data to my GUI and plot it...At the same time I have just done a 1D interpolation(which can be ignored from my vi file)...
What my task is : I need to generate more data points from my unevenly sampled datas and apply a sine series fit to these data points...
Is there any way you could assist me with this??... Any help would be a big deal at this point !!
I am attaching my vi file and txt files...Along with this I am attaching a MATLAB picture about how my result should look...I have simulated the same in MATLAb and it works...but I have no clue how to do it in Labview...:/
(Note: my red dots are the data points and the green curve is my sine series fit done with MATLAB)
Download All
0 Kudos
Message 11 of 25
(1,407 Views)

these attachments are the text files and the Matlab Picture....

Download All
0 Kudos
Message 12 of 25
(1,407 Views)

I have not installed LV 2012 yet so I cannot open your VIs.

 

Let me see if I understand correctly.  The x data points are time.  The y data points are fixed, known in advance, and represent the position of the detectors.

 

If that is correct then it seem to me that your equation is too complicated and may not represent what you are trying to do.  The mirror motion which you are trying to measure has only one amplitude and only one phase.

 

y1(known postion of detector 1) = A*sin(2*pi*f*t1(measured time at y1)+theta)

y2 = A*sin(2*pi*f*t2+theta)

y3 = A*sin(2*pi*f*t3+theta)

y4 = A*sin(2*pi*f*t4+theta)...

 

Where A and theta are the values you want to find from the fitting process.  You appear to have multiple values of t[i] for each value of y[i] as the mirror sweeps the laser across the detector array repeatedly.

 

Lynn

0 Kudos
Message 13 of 25
(1,401 Views)

@Marky1987 wrote:

What my task is : I need to generate more data points from my unevenly sampled datas and apply a sine series fit to these data points...

Is there any way you could assist me with this??... Any help would be a big deal at this point !!


Have you looked at any of the help pages and examples for the nonlinear fitting? f(x,a) requires a VI reference (easiest would be a static VI reference set to strictly typed), not the function output of your model VI. You also should not change the connector patter (you added a knob!). If your model needs aditional information, use the data variant.

0 Kudos
Message 14 of 25
(1,393 Views)

It would really help if you give a bit more information, or example about the frequency. In any case, you seem to be about 90 degrees off, so a cosime seems to be more realistic. However, you should probably fit for the actual phase.

 

In the attached (LabVIEW 2012), I took your data attached above and fit it with your model (after changing sine to cosine). Maybe you can use it as a start to develop your own code. I agree with Lynn that the model seems to be lacking some logic.

 

Download All
Message 15 of 25
(1,381 Views)

Hey Altenbach and Lynn,

 

Thanks a lot guys....

 

@Altenbach : This looks like an ideal solution for my problem!!!!

 

1) I was just given a data of the oscillation of a mirror for one period , which was recorded by a PSD....So basically I had like 100's of time and position intervals.... The mirror was a 100hz sample with a particular voltage(not important).... I will attach this actual file along with this post..

 

2)Just to test my GUI and see if my fit function is possible I had to consider 12 positions and 12 corresponding times randomly out this 100's of data points because my set up will not be a PSD anymore, but 6 photodiodes which gives me 12 time readings at fixed positions...

 

3)My mirror can be designed in such a way that , its intial position can be zero(sine) or with a phase shift(cosine)...Just in this example it has a phase shift...But if my initial position is zero then it would be a sine fit... So I was jus thinking of making my function little more flexible...

 

4) My idea was that, I have "six sine terms" i.e six amplitudes and six phase =  12 unknown coefficients,  corresponding to 12  x(time) and y(position) know values...I can solve this system of equations and get my unknowns out....

 

5) But of this all my main aim is just to fit through this points and get my Amplitude and the deviations of the fit from my data points out... 

 

I dont know if I am still succesful in conveying my idea through you guys... But this vi of yours is one great step for me at this point...

 

6) I have attached the vi you provided me with the sine series fit and it worked fine!!! Could you please tell me how can I add and get my phase coefficients(cn) out as well ( an*sin(n*2pi*f*x+cn)) ...? ..................What ever i try doing I get a broken line 😕

 

@ Lynn : You have got the initial part right...But..

 

1) If you have got this right please ignore it...The a1,a2,a3,a4,a5,a6 and c1...6   are just my harmonics of my phase and amplitude...

 

2) Yes since the mirror is oscillating in time and the positions are fixed I have for each position 2 different times...

 

Thanks a ton again guys,

 

Please provide me any feedback if possible... 

0 Kudos
Message 16 of 25
(1,367 Views)

Forgot about the files...

 

Cheers,

 

Marky

Download All
0 Kudos
Message 17 of 25
(1,366 Views)

Hey Altenbach,

 

I have attached the vi file which i tried modifying your design to suit my task.....I am facing few challenges...Please take a look at this and help me if possible...

 

1) I have fit the sine series function which is shown on the fit model.vi file.... In this I have added different phase coefficients a5,a6,a7,a8,a9.... By adding this phase coefficients and solving the system equation as I mentioned in my previous mail my sine series fuction can identify howmuch the phase is shifted. So there is no need of seeing the data points and then considering a sine or cosine fit (please ignore if you know this)....

But the issue is that these coefficients are not being highlighted  on my front panel and on the guess coefficients??

 

2)Since data points were from a 100hz mirror , the frequency supplied at the fit.vi front panel is 100....After this I manually add the "guess coefficients a5,a6,a7,a8,a9" and give values 0 and run the program again... 

 

Note : Can you please check the results with  the fits : "y = a0*sin(2pi*f*x+a5) + a1*sin(2*2pi*f*x+a6) + a2*sin(3*2pi*f*x+a7) + a3*sin(4*2pi*f*x+a8) + a4*sin(5*2pi*f*x+a9) " and y = a0*sin(2pi*f*x+a5) + a1*sin(3*2pi*f*x+a6) + a2*sin(5*2pi*f*x+a7) + a3*sin(7*2pi*f*x+a8) + a4*sin(9*2pi*f*x+a9) 

They give me different results??

I am really lost............please let me know if you can help me out here  ...

 

Thanks a lot for your patience,

 

Marky

Download All
0 Kudos
Message 18 of 25
(1,335 Views)

The array size of the guesses needs to match the number of parameters in the model. You need to make sure there are 10 (or whatever the number is) elements in the guess array. After resizing the array, make it permanent (right-click array, make current value default) and save the VI.

0 Kudos
Message 19 of 25
(1,330 Views)

Hey Altenbach,

 

Thanks somuch ...If ever you find time for the second issue in my previous mail, please post it sometime ....

 

Thanks again,

 

Marky

 

 

 

 

0 Kudos
Message 20 of 25
(1,327 Views)