💥💥💥💞💞💞欢迎来到本博客❤️❤️❤️💥💥💥
📝目前更新:🌟🌟🌟智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真。
🎉🎉欢迎您的到来🎉🎉
⛅⛅⛅ 📃CSDN主页:Matlab科研室🌈🌈🌈
📚📚📚📋所有代码目录见微信公众号:天天Matlab👨•💻👨•💻👨•💻
1 内容介绍
为准确提取轴承故障特征信息,提出以样本熵为综合目标函数的变分模态分解(variational mode decomposition,VMD)参数优化方法,并改进了诊断流程实现了无需指定参数优化范围的自适应参数优化算法.通过麻雀算法对综合目标函数最小值进行搜索,以确定模态分量个数及惩罚参数的最佳组合.原始故障信号经最佳参数组合下的VMD方法分解为若干个本征模态函数,选择最小综合目标函数值对应的模态分量进行包络解调分析,进而通过模态分量的包络谱判断轴承故障类型.通过实测故障信号分析表明,该方法能够从噪声干扰中有效提取到早期故障信号的微弱故障特征,实现了轴承故障类型的准确判定,验证了该方法的有效性.
2 仿真代码
function SSA_VMD(varargin)
SearchAgents_no = cell2mat(varargin(1));
Max_iteration = cell2mat(varargin(2));
dim = cell2mat(varargin(3));
lb = cell2mat(varargin(4));
ub = cell2mat(varargin(5));
try
imf_write = cell2mat(varargin(6));
catch
imf_write = 0;
end
t = evalin('base', 't');
s = evalin('base', 's');
fs = evalin('base', 'fs');
ST = 0.6;
PD = 0.7;
SD = 0.2;
PDNumber = round(SearchAgents_no * PD);
SDNumber = round(SearchAgents_no - SearchAgents_no * SD);
if (max(size(ub)) == 1)
ub = ub .* ones(1, dim);
lb = lb .* ones(1, dim);
end
X0 = initialization(SearchAgents_no, dim, ub, lb);
X = X0;
fitness = zeros(1, SearchAgents_no);
for i = 1:SearchAgents_no
fitness(i) = fun(X(i, :), s);
end
[fitness, index] = sort(fitness);
BestF = fitness(1);
WorstF = fitness(end);
GBestF = fitness(1);
for i = 1:SearchAgents_no
X(i, :) = X0(index(i), :);
end
Convergence_curve = zeros(Max_iteration, 1);
GBestX = X(1, :);
X_new = X;
gbest_array = zeros(Max_iteration, 2);
for i = 1:Max_iteration
BestF = fitness(1);
WorstF = fitness(end);
R2 = rand(1);
for j = 1:PDNumber
if (R2 < ST)
X_new(j, :) = X(j, :) .* exp(- j / (rand(1) * Max_iteration));
else
X_new(j, :) = X(j, :) + randn() * ones(1, dim);
end
end
for j = PDNumber + 1:SearchAgents_no
if (j > (SearchAgents_no - PDNumber) / 2 + PDNumber)
X_new(j, :) = randn() .* exp((X(end, :) - X(j, :)) / j^2);
else
A = ones(1, dim);
for a = 1:dim
if (rand() > 0.5)
A(a) =- 1;
end
end
AA = A' * inv(A * A');
X_new(j, :) = X(1, :) + abs(X(j, :) - X(1, :)) .* AA';
end
end
Temp = randperm(SearchAgents_no);
SDchooseIndex = Temp(1:SDNumber);
for j = 1:SDNumber
if (fitness(SDchooseIndex(j)) > BestF)
X_new(SDchooseIndex(j), :) = X(1, :) + randn() .* abs(X(SDchooseIndex(j), :) - X(1, :));
elseif (fitness(SDchooseIndex(j)) == BestF)
K = 2 * rand() - 1;
X_new(SDchooseIndex(j), :) = X(SDchooseIndex(j), :) + K .* (abs(X(SDchooseIndex(j), :) - X(end, :)) ./ (fitness(SDchooseIndex(j)) - fitness(end) + 10^ - 8));
end
end
for j = 1:SearchAgents_no
for a = 1:dim
if (X_new(j, a) > ub(a))
X_new(j, a) = ub(a);
end
if (X_new(j, a) < lb(a))
X_new(j, a) = lb(a);
end
end
end
for j = 1:SearchAgents_no
fitness_new(j) = fun(X_new(j, :), s);
end
for j = 1:SearchAgents_no
if (fitness_new(j) < GBestF)
GBestF = fitness_new(j);
GBestX = X_new(j, :);
end
end
X = X_new;
fitness = fitness_new;
[fitness, index] = sort(fitness);
BestF = fitness(1);
WorstF = fitness(end);
for j = 1:SearchAgents_no
X(j, :) = X(index(j), :);
end
disp(['current iteration is: ', num2str(i), ', best fitness is: ', num2str(GBestF)])
gbest_array(i, :) = GBestX;
Convergence_curve(i) = GBestF;
end
Best_pos = GBestX;
flag = 1;
figure(1)
plot(Convergence_curve, 'k-.o', 'linewidth', 1)
legend('最佳适应度')
grid on
xlabel('进化代数')
ylabel('包络熵')
title('SSA进化曲线')
figure(2)
plot(gbest_array(:, 1), 'ks-.', 'linewidth', 1)
grid on
xlabel('进化代数')
ylabel('惩罚因子')
title('惩罚因子的优化过程曲线')
figure(3)
plot(round(gbest_array(:, 2)), 'kv-.', 'linewidth', 1)
grid on
xlabel('进化代数')
ylabel('分解的模态数')
title('分解模态数的优化过程曲线')
alpha = Best_pos(1);
K = round(Best_pos(2));
tau = 0;
DC = 0;
init = 1;
tol = 1e-7;
[u, u_hat, omega] = VMD(s, alpha, tau, K, DC, init, tol);
[m, ~] = size(u);
m = m + 1;
figure(4)
for i = 1:m - 1
subplot(m, 1, i)
plot(t, u(i, :), 'b-', 'linewidth', 1)
ylabel(['IMF', num2str(i)]);
end
res = s' - sum(u, 1);
subplot(m, 1, m)
plot(t, res, 'b-', 'linewidth', 1)
ylabel('Res');
xlabel('t/s')
figure(5)
for i = 1:m - 1
subplot(m, 1, i)
[cc, y_f] = plot_fft(u(i, :), fs, 1);
plot(y_f, cc, 'b', 'LineWIdth', 1);
ylabel(['FFT of IMF', num2str(i)]);
end
subplot(m, 1, m)
[cc, y_f] = plot_fft(res, fs, 1);
plot(y_f, cc, 'b', 'LineWIdth', 1);
ylabel('FFT of Res');
xlabel('f/Hz')
fig_text(flag)
% figure(6)
%
% imshow(a. personal_id);
% title( 'Color', 'red', 'FontSize', 16,...
% 'HorizontalAlignment', 'center',...
% 'Interpreter', 'none')
%
% fprintf_result(Best_pos, s);
%
% if imf_write == 1
% xlswrite('imf结果.xlsx', u', 'u', 'A1');
% xlswrite('imf结果.xlsx', u_hat, 'uhat', 'A1');
% xlswrite('imf结果.xlsx', omega, 'omega', 'A1');
% end
3 运行结果
编辑
4 参考文献
[1]胡鸿志, 覃畅, 管芳,等. 基于麻雀搜索算法优化支持向量机的刀具磨损识别[J]. 科学技术与工程, 2021, 21(25):7.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。