Smooth vector data with a specific step

조회 수: 4(최근 30일)
Lev Mihailov
Lev Mihailov 2022년 4월 4일
댓글: Mathieu NOE 2022년 4월 6일
I need to smooth the data, but the smooth function flips the response of the data, which makes things a little more difficult
x = rand(1,4097);
y = rand(1,4097);
z1=smooth(x(1:10),x(1:10),0.8,'rloess')'; % len(1,10)
z2=smooth(x(11:21),x(11:21),0.8,'rloess')'; % len(,10)
z=[z1,z2] % for each part z=[z1,z2... z(end)]
% the code that I am currently using, but I do not understand why such an answer
step = 10;
for j = 1:step:size(x,2)-step
a = y(j:j+1);
b = x(j:j+1);
z(1,j+1)= smooth(a,b,0.8,'rloess')';
The answer "z" is not correct (it's a 2,4097 matrix) and there are a lot of zeros in the data.
Thank you in advance


Mathieu NOE
Mathieu NOE 2022년 4월 4일
not sure what you are trying to do , but if it's about splitting data in buffers and doing some math on the buffers (mean , rms, smooth,..), here maybe some code to help you :
% dummy data
x= 1:n;
y = sin(2*pi*x./max(x))+rand(1,n);
buffer = 10; % nb of samples in one buffer (buffer size)
overlap = 5; % overlap expressed in samples
%%%% main loop %%%%
m = length(y);
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
mean_data(ci) = mean(y(start_index:stop_index)); %
x_mean = x(time_index);
  댓글 수: 3
Mathieu NOE
Mathieu NOE 2022년 4월 6일
maybe check that you have not used or initialized some of my code's variables from another portion of code that would change arrays dimensions (from my code version)

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by