How to use 'resample' function?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Adam Danz
el 6 de En. de 2021
Editada: Adam Danz
el 6 de En. de 2021
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
Respuestas (0)
Ver también
Categorías
Más información sobre Multirate Signal Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!