1
$\begingroup$

I have asignal and I would like to decompose it into two..

this is the datasetTot of both signals

ListPlot[datasetTot, PlotStyle -> {Black, Black}]   

enter image description here

I know that this signal is a sum of two signals whose shape is like this

enter image description here

My question is: can I get the green and red signals separately from the original data datasetTot?

update

the green and red signals are

green={-2 Tanh[1 - x] + Tanh[x], Tanh[x] + 2 Tanh[1 + x]}
red={3/2 (Tanh[2 x] - Tanh[2 (1 + x)]), 3/2 (Tanh[2 - 2 x] + Tanh[2 x])}
$\endgroup$
5
  • $\begingroup$ Can you assume that you know the green and red signals ahead of time? (Data/definitions for them are not provided in your example). If so, it seems like you could NMinimize a least-squares expression for the black signal as a linear combination of the red and green signals (with two real parameters describing the coefficients of the red and green contributions) $\endgroup$ May 26 at 10:35
  • 1
    $\begingroup$ Do you know equations that red and green curves are described with? $\endgroup$
    – yarchik
    May 26 at 10:45
  • $\begingroup$ I only know how the profiles of the two signals would be, as I showed in green and red which is synthesized data. $\endgroup$ May 26 at 11:42
  • $\begingroup$ Please provide the equations for the two profiles. Afterwards, you could use NonlinearModelFit to get the two coefficients (as Joshua already proposed). $\endgroup$
    – Domen
    May 26 at 12:37
  • $\begingroup$ kindly, see update for the green and red profiles. $\endgroup$ May 26 at 13:15

1 Answer 1

6
$\begingroup$

Not very elegent approach ... You fit the linear combination of both components to obtain the coefficients (which in your case seem to be 1). Then, you separate the signal by subtracting one of the components (I used the green one).

data = (* ... *);

green = {-2 Tanh[1 - x] + Tanh[x], Tanh[x] + 2 Tanh[1 + x]};
red = {3/2 (Tanh[2 x] - Tanh[2 (1 + x)]), 3/2 (Tanh[2 - 2 x] + Tanh[2 x])};

fit = MapThread[
   NonlinearModelFit[#1, g #2 + r #3, {g, r}, x] &, {data, green, 
    red}];

Show[ListPlot[data], Plot[{fit[[1]][x], fit[[2]][x]}, {x, -4, 4}]]

Through[fit["BestFitParameters"]]

(* {{g -> 1., r -> 1.}, {g -> 1., r -> 1.}} *)

Mathematica graphics

separated = 
  Table[{#[[1]], #[[2]] - g green[[i]], g green[[i]]} /. 
       fit[[i]]["BestFitParameters"] /. x -> #[[1]] & /@ 
    data[[i]], {i, 2}];

Show[{
  ListPlot[separated[[All, All, {1, 3}]], PlotRange -> All, PlotStyle -> Green],
  ListPlot[separated[[All, All, {1, 2}]], PlotRange -> All, PlotStyle -> Red]
  }]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.