# Analyze between two consecutive waves.

I collect electrical recordings from the retina in response to light stimuli.

These waves (responses) have data points ranging from 50,000 to 20,000 where the X-axis represents time and the Y-axis represents amplitude.

I just want to focus on the first 10000 data points between two consecutive waves (say A and B). My objective is to apply a "CurveFit Line" function {f(x)=a+(b)*x} between these two points. The fit function provides coefficient values in terms of "a" and "b".

Ultimately, these coefficient values are used to subtract the first wave A. I.e. WaveA=WaveA-{a+(b)*x}.

The only external input would be the distance between two points (in seconds) would have to be manually entered as the value varies between traces.

Can you help me deduce a code/function that can run as described?

Thanks.

Could you perhaps give an example? It's not clear to me what you're trying to do.

Does 'between two waves' mean that A is a wave holding the dependent variable and B the independent variable?

A good strategy is to make a fit using the built-in curve fitting dialog. There are plenty of options for selecting a subrange and so on. If you can fit one pair of waves successfully, the CurveFit command recorded in the history window will be a good starting point for building an automated routine. Post that command here if need help.

Dear Tony,

I appreciate your prompt response. I've included a pxp file containing two response waves, namely R1 and R10. Each response is entirely independent of the other, with their own sets of dependent and independent variables. Specifically, R1 comprises 200,000 numPoints while R10 consists of 60,000 numPoints. Let's assume that R10 was recorded 10 seconds after R1 (referenced as Graph0).

For both waves, the initial 1-second interval is considered baseline. Consequently, my interest lies solely in this segment, spanning numPoints 0 to 9,999 (referred to as Table 1 and Table 0). In this context, I've incremented all datapoints by 10 seconds for Timer_R10.

By plotting these numPoints (Graph 2), I intend to execute a "CurveFit Line" function {f(x) = a + (b)*x} across these points, yielding a fit line (depicted in black on Graph 2). The resulting coefficient values (autogenerated in command window) are as follows:

• a = 3.1445e-07 ± 1.26e-08
• b = -3.3425e-06 ± 1.69e-09

Subsequently, I aim to correct the drift (excluding the baseline) for the initial trace, R1, utilizing these coefficients as follows:

R1 = R1 - {3.1445e-07 + (-3.3425e-06)*x}

I am keen to explore the feasibility of achieving these tasks through a simple code or function, where only the difference between the two responses needs to be manually provided.

Thank you,

Rajan.

If I understand, you want to adjust the baseline y value on the second data set to be comparable to the baseline y value of the first set. Let's call the two waves waveA (the one that starts at 0) and waveB (the one that starts at 10).

Use WaveStats over the range of the baselines to obtain averages Aave and Bave.

- duplicate/O waveB waveBSOURCE // keep the original for reference

- waveB -= (Bave - Aave)

If you need to recover your source

- duplicate/O waveBSOURCE waveB

One way to get user input is to use Prompt and DoPrompt commands in your code.

DisplayHelpTopic "The Simple Input Dialog"

You can use make to create a pair of waves for fitting:

Make/N=20000/free wx, wy
wx[0,9999] = Timer_R1[p]
wy[0,9999] = R1[p]
wx[10000,19999] = Timer_R10[p-10000] + offset
wy[10000,19999] = R10[p-10000]

and then do the fitting and make the wave assignment as you have described above.