![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031705/image.png)
how can I calculate movmean from 1 periode wave data?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
christina widyaningtyas
el 14 de Jun. de 2022
Respondida: Peter Perkins
el 14 de Jun. de 2022
I have data :
x-axis is datetime - experiment time start (called as t=0)
y-axis is pressure
How to calculate the moving average of one periode wave data (example like this figure)?
X is time 00:21:00 to 00:22:58
Y is pressure 931 to 931
I use 2016b and sometimes 2020 Matlab version
I hope someone can help me, please
thank you
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031610/image.jpeg)
0 comentarios
Respuesta aceptada
Mathieu NOE
el 14 de Jun. de 2022
hello
we can use the peaks to compute this value as well
you can use islocalmax (or islocalmin) to locate local peaks.
Some smoothing may help if yur data are a bit noisy or "hairy"
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031705/image.png)
see demo below
clc
clearvars
% demo on dummy data
n=1000;
x = linspace(0,10,n)';
y = 931*(0.9+0.1*cos(x/10))+10*sin(3*x-1)+ 5*rand(n,1);
% some smoothing first
ys = smoothdata(y,'gaussian',25);
% find positive local maxima
[tf, P] = islocalmax(ys,'MinProminence',std(ys)/3);
x_peak = x(tf);
y_peak = ys(tf);
% compute average of pressure on cycle by cycle
for ci = 1:numel(x_peak)-1
ind = (x>=x_peak(ci) & x<x_peak(ci+1));
y_avg(ci) = mean(y(ind));
x_avg(ci) = (x_peak(ci) + x_peak(ci+1))/2; % time value (plot) = mid point between two x_peak values
end
figure(1)
plot(x,y,'b',x,ys,'g',x_peak,y_peak,'dr',x_avg,y_avg,'+-k','linewidth',2,'markersize',12);
xlabel('time')
ylabel('pressure')
legend('raw signal','filtered signal','peaks','averaged cycle value');
0 comentarios
Más respuestas (1)
Peter Perkins
el 14 de Jun. de 2022
In addition to what Mathieu suggests, there are similar things shown in these examples, especially the first one:
0 comentarios
Ver también
Categorías
Más información sobre Data Import and Analysis 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!