emd matlab代码

close all
clear
clc

% 定义时间变量
t = 0:0.01:10; %010,步长为0.01

% 定义不同的频率和相位
f1 = 0.5;
f2 = 1;
f3 = 2;
phi1 = 0;
phi2 = pi/4;
phi3 = pi/6;

% 添加一个线性趋势
linear_trend = 0.2 * t;

% 添加噪声
noise = 0.1 * randn(size(t));

% 生成复杂的合成信号
x = sin(2 * pi * f1 * t + phi1) + 0.5 * cos(2 * pi * f2 * t + phi2) + 0.3 * sin(2 * pi * f3 * t + phi3) + linear_trend + noise;

% 获取不同时间下的数据自相关系数
Rxtemp = [];
for k=1:length(t)
    R_xx = max(xcorr(x(1,1:k)))/(k*2);
    Rxtemp = [Rxtemp R_xx];
end
figure;
plot(Rxtemp)

% n为显示分量个数
n =8;
% 绘制原始信号
figure;
subplot(n, 1, 1);
plot(t, x);
title('原始信号');


% 使用EMD函数进行分解
imf = emd(x);

temp=[];
Rtemp =[];
% 显示IMFs
for k = 1:size(imf, 2)
    subplot(n ,1, k + 1);
    plot(t, imf(:, k));
    %分量累加和是否近于0
    temp = [temp sum(imf(:,k))];
    %分量和原信号的相关系数
    R = corrcoef(x, imf(:,k));
    Rtemp = [Rtemp R(1,2)];
    title(['IMF ', num2str(k)]);
end
figure;
plot(temp)
hold on 
plot(t,zeros(1,length(t)),'b--')
title('分量累加和是否近于0')
figure;
plot(Rtemp)
title('分量和原信号的相关系数')

%m为高低频分界分量,m以上为高频信号重构(不包括m),m以下为低频信号重构(包括m)
m=1;
% 绘制重构信号
figure;
subplot(4, 1, 1);
plot(t, x);
title('原始信号 m = '+string(m));

subplot(4, 1, 2);
plot(t,  sum(imf(:,1:m)', 1));
title('高频信号');

subplot(4, 1, 3);
plot(t,  sum(imf(:,m+1:end)', 1));
title('低频信号');
subplot(4, 1, 4);
plot(t,  sum(imf(:,1:m)', 1)+sum(imf(:,m+1:end)', 1));
title('高频+低频信号');

在这里插入图片描述

### EMD Algorithm Code Implementation and Example The Earth Mover's Distance (EMD) is a measure of the distance between two probability distributions over a region \( D \). It has applications in image retrieval, natural language processing, and machine learning. Below is an explanation of how to implement EMD using Python with libraries like `scipy` or custom implementations. #### Using Scipy for EMD Calculation Python’s SciPy library provides functionality for calculating EMD through its Optimize module: ```python from scipy.stats import wasserstein_distance # Define two discrete probability distributions distribution_a = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6] distribution_b = [0.1, 0.2, 0.3, 0.2, 0.1, 0.1] # Calculate Wasserstein distance (Earth Mover's Distance) distance = wasserstein_distance(distribution_a, distribution_b) print(f"The Earth Mover's Distance is {distance}") ``` This method uses the Wasserstein metric from statistics which aligns closely with EMD concepts[^4]. #### Custom Implementation Without Libraries For educational purposes, one may also write their own version without relying on external packages: ```python import numpy as np def emd_custom(p, q): """ Compute Earth Mover's Distance manually. Parameters: p : list[float], first histogram/distribution normalized q : list[float], second histogram/distribution normalized Returns: float representing earth mover's distance value """ assert len(p)==len(q),"Both histograms must be same length" cdf_p = np.cumsum(p) cdf_q = np.cumsum(q) return np.linalg.norm(cdf_p - cdf_q, ord=1) # Example usage p = [0.1, 0.2, 0.3, 0.2, 0.1, 0.1] q = [1/6]*6 result = emd_custom(p,q) print("Custom EMD:", result) ``` In this case, cumulative distribution functions are compared directly via L1 norm computation after normalization steps[^5]. #### Notes About Accuracy Improvement Techniques When attempting improvements towards achieving higher accuracies within models utilizing techniques similar to those mentioned earlier regarding convolution layers combined with batch normalizations followed by activations could potentially enhance performance metrics when dealing complex datasets requiring fine tuning parameters effectively[^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值