0

How can I resample my [t x] matrix and fill the gap of resampled data with interpolation data in Matlab?

Input is the upper signal output is lower signal in the image.The output should be [tout xout] with similar dimensions to [t x]. The middle points of resampled data should be interpolated.

Here is a visualisation of my desired output:

Image of Desired output Image of Data and desired output

t = [0.2 0.25 0.3 0.35 0.4 0.45 0.5]                                                   % Original Time Vector
x = [1 2 2.5 2.4 3 2 1]                                                   % Original Data Vector
L = length(t);
tv = linspace(min(t), max(t), L);                             % Time Vector For Interpolation
dv = interp1(t, x, tv, 'linear');                             % Interpolated Data Vector
Ts = mean(diff(tv));
Jomer
  • 3
  • 3
  • Read about interp1, fillgaps. – Siva Srinivas Kolukula Apr 02 '19 at 11:39
  • So what is the problem here? – Irreducible Apr 02 '19 at 11:42
  • The code doesn't include resampling – Jomer Apr 02 '19 at 11:45
  • You can use [`randsample`](https://www.mathworks.com/help/stats/randsample.html) or [`datasample`](https://www.mathworks.com/help/stats/datasample.html) if you have the Statistics toolbox. Related [post](https://stackoverflow.com/a/53524024/8239061) with full reproducible example for [`interp1`](https://www.mathworks.com/help/matlab/ref/interp1.html). See [Filling missing data in a dataset](https://stackoverflow.com/q/29591624/8239061) for another example. – SecretAgentMan Apr 02 '19 at 11:45
  • See [this post](https://stackoverflow.com/a/54859855/8239061) for how to randomly sample from original data (multiple options). – SecretAgentMan Apr 02 '19 at 11:50
  • can u help me write a code for that? I know how to do it in one dimention but resampling and interpolation between x and y vector is a bit hard. I really appreciate your help. – Jomer Apr 02 '19 at 11:51
  • Have you looked at these reproducible examples and the documentation links (which also have examples)? What part are you struggling with? – SecretAgentMan Apr 02 '19 at 12:05
  • yes i looked but examples pertain to using randsample in 1 column matrix only. I have both time (t) and (x) data. if I want to resample at 0.03 second then i should get the equivalent x value in the same row. – Jomer Apr 02 '19 at 12:10
  • 1
    @JomerSenorin I have the impression you dont understand interpolation / resampling. Take your time to read the links which SecretAgentMan posted and apply them to your data. You will profit from this by far more than just getting code which you dont understand – Irreducible Apr 02 '19 at 12:43
  • i understand my problem correctly. just like what i said before my data has t and x column。Maybe you can answer with code and explain it? – Jomer Apr 02 '19 at 13:23
  • @JomerSenorin A *small* numerical example showing the output of your current approach and your desired output would probably be helpful at this point. – beaker Apr 02 '19 at 14:45
  • I added numerical example please check. Thanks – Jomer Apr 02 '19 at 15:07
  • 1
    Add data as data, not images. You've shown you understand how to include text formatted as code, include your [mcve] the same... – Wolfie Apr 02 '19 at 15:36
  • The reason `interp1` doesn't do anything in your example is that `tv` is exactly the same as `t`. – beaker Apr 03 '19 at 18:17

0 Answers0