Methods to make(fit) the samples of two signals for averaging them

Hello,
I want to get the average of two signals but the number of samples(values) of the two are not equal.One method to make this possible is by using interpolation and here is the demo by Image Analyst for this but the values of the resultant(interpolated)signal are not equal to that of the real signal values.
Can someone explain if there are other methods available to fit the number of samples between two signals.
Thanks.

6 件のコメント

Gova ReDDy
Gova ReDDy 2014 年 1 月 15 日
Hi, can someone explain a method that can solve the averaging problem if two signal needed to be averaged doesn't have the same number of samples.
Thanks.
Amit
Amit 2014 年 1 月 16 日
Can you post example data please?
Gova ReDDy
Gova ReDDy 2014 年 1 月 16 日
Yes, the both signlas data(s1 and s2) are attached and the way I followed is
%------s1 interpolation with s2----------%
s1_inter=interp1(s1(1,1:length(s1)), s1,s2(1,1:length(s2)));
plot(s1);hold on;plot(s2,'-g');plot(s1_inter,'-r');
for the resultant interpolated signal some of them are not available.
%------s2 interpolation with s2----------%
s2_inter=interp1(s2(1,1:length(s2)), s2,s1(1,1:length(s1)));
plot(s1);hold on;plot(s2,'-g');plot(s2_inter,'-r');
The resultant interpolated signal is same as the other signal.
can I know the best way to do the samples fit.
Otutput:
Image Analyst
Image Analyst 2014 年 1 月 16 日
You're not using interp correctly. Check what the first two arguments are supposed to be - it's not what you have.
Amit
Amit 2014 年 1 月 16 日
I think what he want is somehow get both data to be of same size, so he can average it. and yeah, the interpolation used in his code is no better than using y=x.
Image Analyst
Image Analyst 2014 年 1 月 16 日
I gave him code to make them the same size in http://www.mathworks.com/matlabcentral/answers/111930#answer_120465 and then to average them. He accepted but then he changed it to the code above, which broke it.

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

回答 (1 件)

Amit
Amit 2014 年 1 月 16 日

0 投票

Your s1 and s2 are 1x363 and 1x411 matrixes. Now what you're interpolating is essentially interp1(s1,s1,_blah_) which is simply a straight line. Moreover you're just plotting plot(s1) etc, which is essentially plot(1:length(s1),s1) etc. The problem here is that the number of elements in your matrixes are different and the plot will look like this.
Is there a 'x' values corresponding to s1 and s2?

2 件のコメント

Gova ReDDy
Gova ReDDy 2014 年 1 月 16 日
No, I don't have.
Amit
Amit 2014 年 1 月 16 日
編集済み: Amit 2014 年 1 月 16 日
Okay, in that case I think you can do something like this (if I understand correctly).
In case length(s1)<length(s2), as in your case
s1_x = linspace(1,length(s1),length(s2));
s2_int = interp1(s2_x,s2,1:length(s1));
plot(s1);hold on;plot(s2_x,s2,,'-g');plot(s2_int,'-r');
%%For averaging
avg_s1s2 = mean([s1;s2_int]);
You dont have to interpolate s1 here.

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

カテゴリ

製品

タグ

質問済み:

2014 年 1 月 14 日

コメント済み:

2014 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by