How to use 'resample' function?
조회 수: 12 (최근 30일)
이전 댓글 표시
I have a set of data (response vs. time) with 2000+ data points, collected over the course of 500 seconds. I would like to reduce the number of data points to 100 by using only data points collected every 5 seconds, but my sampling frequency does not provide a data point at 5 second intervals. After searching MATLAB Answers, it appears many people use the resample function. I have several questions:
- What is the difference between using the resample function and linear interpolation?
- I do not understand what the upsampling (p) and downsampling (q) factors are. If I set p=1 and q=1, will I just be linear interpolating? Are p and q important to reducing edge effects? I have found that if I set p and q to 1, there are no edge effects, why is this? See example below.
I have attempted to implement the resample function as follows with padded data at the beginning and end as suggested by this MATLAB Answer:
fs=1/5;
x=time; % time vector in sec
y=response; % change in response vector
xpad = [repmat(x(1), 1, 20)'; x; repmat(x(end), 1, 20)'];
tpad = [repmat(y(1), 1, 20)'; y; repmat(y(end), 1, 20)'];
[yB,xB]=resample(tpad,xpad,fs1,1,1,'linear'); %p=1, q=1


댓글 수: 7
Adam Danz
2021년 1월 6일
편집: Adam Danz
2021년 1월 6일
I just dealt with this problem a few days ago. I was analyzing data collected at 150Hz which is 6.667ms intervals but since the compute stored the data at ms resolution, the intervals were either 6 or 7 ms. I preferred to work with the raw data rather than interpolated data.
If your sampling frequency variation is not very large and if you have the sample timestamps you can differentiate that timestamps to get the sampling interval for each sample. Then you could subsample your data based on the cumulative intervals which will result in approximately equal segments of time.
For example,
timestamps = [6 13 20 26 32 38 45 52 59 66 73 79 86 92 99 106 112 118 124 131 138 145 151 158 164 171 178 184 191 198 204 210 216 222 229 236]; %ms or some other unit of time
data = 1:numel(timestamps); % sampled data (arbitrary)
dt = diff([0,timestamps]); % sampling intervals (ms)
desiredInterval = 20; % Desired sub-sampling rate (ms)
idx = find(diff([-inf, mod(cumsum(dt), desiredInterval)]) <=0) +1; % index of subsampled values
subsampledData = data(idx); % subsampled data
diff(timestamps(idx)) % the actual subsampled intervals which should be close to desiredInterval if your sampling freq variation is not too high
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!