How to fix a shift issue after taking hamonic mean?

1 回表示 (過去 30 日間)
Nisar Ahmed
Nisar Ahmed 2022 年 8 月 24 日
コメント済み: Mathieu NOE 2022 年 9 月 12 日
Hi everyone,
In the figure below, the red curve (Mdry) is the harmonic average of blue curve Md by using moving mean of 4 values. Due to harmic mean the red peak has been shifted a bit as shown in figure. How can I fix it? I have attached the data of both Md and Mdry. I am using following code to create a haromic mean (in such a way that the length of both Md and Mdry should remain same -- at the end).
Mdry = zeros(size(Md));
for k=1:length(Md)-3
Mdry(k)=harmmean(Md(k:k+3));
end
k = length(Md)-2;
Mdry(k) = harmmean(Md(k:k+2));
k = length(Md)-1;
Mdry(k) = harmmean(Md(k:k+1));
k = length(Md);
Mdry(k) = Md(k);

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 9 月 2 日
hello
is there a reason why the harmonic averaging is needed
here I compared it with a standard smoothing function with gaussain window (odd length) - yellow trace
seems to get similar results in terms of smoothing while better keeping peaks positions
Mdry = zeros(size(Md));
for k=1:length(Md)-3
Mdry(k)=my_harmmean(Md(k:k+3));
end
k = length(Md)-2;
Mdry(k) = my_harmmean(Md(k:k+2));
k = length(Md)-1;
Mdry(k) = my_harmmean(Md(k:k+1));
k = length(Md);
Mdry(k) = Md(k);
% my suggestion
Mdry2 = smoothdata(Md,'gaussian',7); % NB : odd window length to keep peak position closest to original position
plot(Md)
hold on
plot(Mdry)
plot(Mdry2)
hold off
function out = my_harmmean(in)
out = numel(in)./(sum(1./in));
end
  4 件のコメント
Nisar Ahmed
Nisar Ahmed 2022 年 9 月 12 日
編集済み: Nisar Ahmed 2022 年 9 月 12 日
@Mathieu NOE thanks, I have to check it and then respond you... I have been badly involved some other assigmenets. that's why delayed.
Since I got answer after many dats of posting so become busy in other stuff
Mathieu NOE
Mathieu NOE 2022 年 9 月 12 日
ok - no problem; take your time !
all the best

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by