codebraker
codebraker

Reputation: 118

Resample time based column array as per sampling time in Matlab

I need to run a simulation with sample time of

tsample = 0.01 ; % seconds

I have a table such as below

enter image description here

I need to resample each column in input table such that value of the input Time vector gets equally spaced based on tsample values.

For the [Time] column I achieved this by following code

    simTime         = max(tests.(test_names{i}).Times);   % Seconds

    % Interpolate the time and frequency values as per sample time
    numSteps        = simTime/tsample;    
    time            = tsample * [0:(numSteps-1)]';

What I need to do now is resize the frequency (f) values such that it shall be filled with previous values until a new value is found in column;

Time f
0 50
.... 50
4.99 50
5.00 49.65
.... 49.65
19.99 49.65
20.00 49.80

I am confused whether I should use fillmissing or resample or interp1. The examples I am following for these seem kind of different than what I wish to achieve here.

Any help would be really appreciated. Thank you.

Upvotes: 0

Views: 65

Answers (1)

codebraker
codebraker

Reputation: 118

Ok, I tried experimenting with more examples for interp1 and this solved my issue.

freq = interp1(tests.Times, tests.fHz, time, 'previous');

I was earlier unaware of the 'previous' option Should have searched the documentation more extensively.

Upvotes: 1

Related Questions