matlab中的twomodegauss函数-双峰高斯函数

文章搬运于:http://blog.sina.com.cn/s/blog_4fc818ea0101l8kn.html


function p = twomodegauss(m1, sig1, m2, sig2, A1, A2, k)
%TWOMODEGAUSS Generates a bimodal Gaussian function.
%TWOMODEGAUSS产生一个双峰的高斯函数
%  P = TWOMODEGAUSS(M1, SIG1, M2, SIG2, A1, A2, K)generates a bimodal,
%  Gaussian-like function in the interval [0, 1]. P  is a 256-element vector
%  normalized so that SUM(P) equals 1. The mean and standard deviation of
%  the modes are (M1, SIG1) and (M2, SIG2), respectively. A1 and A2 are the
%  amplitude values of the two modes. Since the output is normalize, only
%  the relative values of A1 and A2 are important. K is an offset value
%  that raises the “floor” of the function. A good set of values
%  to try is M1 = 0.15, SIG1 = 0.05, M2 = 0.75, SIG2 = 0.05, A1 = 1, A2 =
%  0.07,and K = 0.002.
%  P = TWOMODEGAUSS(M1, SIG1, M2, SIG2, A1, A2, K)在区间[0, 1]上产生一个
%  双峰类高斯的函数。P是标准化的包含256个元素的向量,从而SUM(P)=1.双峰各自的
%  均值和标准差是(M1, SIG1) 和 (M2, SIG2).A1和A2是双峰的峰值。当输出为标准化时
%  A1和A2的相对值比较重要。K是基线,一个比较好的取值集是M1 = 0.15,
%  SIG1 = 0.05, M2 = 0.75, SIG2 = 0.05, A1 = 1, A2 =0.07和 K = 0.002.
 
c1 = A1 * (1 / ((2 * pi) ^ 0.5) * sig1);
k1 = 2 * (sig1 ^ 2);
c2 = A2 * (1 / ((2 * pi) ^ 0.5) * sig2);
k2 = 2 * (sig2 ^ 2);
z = linspace(0, 1, 256);

p = k+c1*exp(-((z-m1).^2)./k1)+c2*exp(-((z-m2).^2)./k2);
p = p./sum(p(:));

 

例子:

>> p = twomodegauss(0.15,0.05, 0.75, 0.05,1, 0.07, 0.002);
>> plot(p)

matlab中的twomodegauss函数-双峰高斯函数

>> p = twomodegauss(0.15,0.05, 0.4, 0.05,1, 0.07, 0.002);
>> figure,plot(p)
matlab中的twomodegauss函数-双峰高斯函数

>> p = twomodegauss(0.15,0.05, 0.9, 0.05,1, 0.07, 0.002);
>> figure,plot(p)
matlab中的twomodegauss函数-双峰高斯函数

   通过比较上面的三个图像,可以发现,当参数m2改变时,m1和m2之间的相对距离发生变化可以导致两个峰的距离改变,即:当m1和m2之间的相对距离变小时,双峰之间的距离也随之变小;m1和m2之间的相对距离变大时,双峰之间的距离也随之增大。可以得出一个有效的结论:即均值m1和m2之间的相对距离影响双峰高斯函数的双峰距离。
>> p = twomodegauss(0.15,0.05, 0.75, 0.3,1, 0.07, 0.002);
>> figure,plot(p)
matlab中的twomodegauss函数-双峰高斯函数

>> p = twomodegauss(0.15,0.05, 0.75, 0.01,1, 0.07, 0.002);
>> figure,plot(p)
matlab中的twomodegauss函数-双峰高斯函数

    通过比较图1,4,5,可以发现,当sig2变化时,第二个峰的高度以及宽度发生了变化,即第二个峰的分布状态改变,随着sig2的增大,第二个峰的高度和宽度也随之增大,即分布状态变大。可以得到结论:标准差影响各自峰的分布状态。
    基线K以及幅值A1,A2的变化可以通过相似的方法得到。