Downsampled data exceeds the input data
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Chandramouli Jambunathan
am 18 Nov. 2022
Kommentiert: Chandramouli Jambunathan
am 18 Nov. 2022
I have an input data sampled at 64 Hz and I want it converted to 60Hz. I tried using 'resample' function and 'downsample' function within matlab,but in both the cases the output data exceeds the input data at some sample points. For example, the input data contains angles in degrees which is under -180 deg to +180 deg, but the downsampled data contains 220 deg,which is wrong. how to avoid these?
In the attached picture, you can find all the input and output are overlayed. Can someone please help me?
2 Kommentare
Mathieu NOE
am 18 Nov. 2022
hello
for the resampling task , use interp1 with a new time vector defined at rate = 60 Hz
to avoid data above / below +/- 180 ° use wrap
Akzeptierte Antwort
Mathieu NOE
am 18 Nov. 2022
a demo is maybe more efficient here
so the original data gets resampled at 60 Hz by using only the start / end points of the time vector of the original data (sampled at 64 Hz)
the two data sets do match visually on the graph even though the points are not on the same grid (of course)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1198643/image.png)
samples=1000;
% original data at 64 Hz rate
dt1 = 1/64;
t1= 1 + (0:samples-1)*dt1;
y1 = 180*(square(t1));
plot(t1,y1,'b-*')
% resample the data at 60Hz
dt2 = 1/60;
t2= t1(1):dt2:t1(end); % NB wee use only the first and last value of t1 to create t2
y2 = interp1(t1,y1,t2);
plot(t1,y1,'b',t2,y2,'r')
2 Kommentare
Weitere Antworten (1)
Jan
am 18 Nov. 2022
A linear interpolation avoids output points outside the range of input point. Use interp1 or the modern and faster griddedInterpolant .
A fast C-mex function for this job: https://www.mathworks.com/matlabcentral/fileexchange/25463-scaletime
3 Kommentare
Jan
am 18 Nov. 2022
I do not understand the meaning of "Both 'interp1' and 'griddedInterpolant' function expects specific data points". But Mathieu has show already, how to use these interpolation methods.
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!