在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例C/C++语言基础 → VMD算法分解信号

VMD算法分解信号

C/C++语言基础

下载此实例
  • 开发语言:C/C++
  • 实例大小:1.96KB
  • 下载次数:30
  • 浏览次数:1637
  • 发布时间:2019-03-20
  • 实例类别:C/C++语言基础
  • 发 布 人:crazycode
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 算法 VMD 信号

实例介绍

【实例简介】利用VMD可以很好的分解信号,可以分解滚动轴承的原始数据和自己的信号仿真数据,VMD算法,带注释解析,方便查看和理解,可直接使用。

【实例截图】


【核心代码】

function [u, u_hat, omega] = VMD(signal, alpha, tau, K, DC, init, tol)
% Variational Mode Decomposition
% Authors: Konstantin Dragomiretskiy and Dominique Zosso
% zosso@math.ucla.edu --- http://www.math.ucla.edu/~zosso
% Initial release 2013-12-12 (c) 2013
%
% Input and Parameters:
% ---------------------
% signal  - the time domain signal (1D) to be decomposed
% alpha   - the balancing parameter of the data-fidelity constraint
% tau     - time-step of the dual ascent ( pick 0 for noise-slack )
% K       - the number of modes to be recovered
% DC      - true if the first mode is put and kept at DC (0-freq)
% init    - 0 = all omegas start at 0
%                    1 = all omegas start uniformly distributed
%                    2 = all omegas initialized randomly
% tol     - tolerance of convergence criterion; typically around 1e-6
%
% Output:
% -------
% u       - the collection of decomposed modes
% u_hat   - spectra of the modes
% omega   - estimated mode center-frequencies
%
% When using this code, please do cite our paper:
% -----------------------------------------------
% K. Dragomiretskiy, D. Zosso, Variational Mode Decomposition, IEEE Trans.
% on Signal Processing (in press)
% please check here for update reference:
%          http://dx.doi.org/10.1109/TSP.2013.2288675
 
 
 
%---------- Preparations
 
% Period and sampling frequency of input signal
save_T = length(signal);
fs = 1/save_T;
 
% extend the signal by mirroring
T = save_T;
f_mirror(1:T/2) = signal(T/2:-1:1);
f_mirror(T/2 1:3*T/2) = signal;
f_mirror(3*T/2 1:2*T) = signal(T:-1:T/2 1);
f = f_mirror;
 
% Time Domain 0 to T (of mirrored signal)
T = length(f);
t = (1:T)/T;
 
% Spectral Domain discretization
freqs = t-0.5-1/T;
 
% Maximum number of iterations (if not converged yet, then it won't anyway)
N = 500;
 
% For future generalizations: individual alpha for each mode
Alpha = alpha*ones(1,K);
 
% Construct and center f_hat
f_hat = fftshift((fft(f)));
f_hat_plus = f_hat;
f_hat_plus(1:T/2) = 0;
 
% matrix keeping track of every iterant // could be discarded for mem
u_hat_plus = zeros(N, length(freqs), K);
 
% Initialization of omega_k
omega_plus = zeros(N, K);
switch init
    case 1
        for i = 1:K
            omega_plus(1,i) = (0.5/K)*(i-1);
        end
    case 2
        omega_plus(1,:) = sort(exp(log(fs)   (log(0.5)-log(fs))*rand(1,K)));
    otherwise
        omega_plus(1,:) = 0;
end
 
% if DC mode imposed, set its omega to 0
if DC
    omega_plus(1,1) = 0;
end
 
% start with empty dual variables
lambda_hat = zeros(N, length(freqs));
 
% other inits
uDiff = tol eps; % update step
n = 1; % loop counter
sum_uk = 0; % accumulator
 
 
 
% ----------- Main loop for iterative updates
 
 
 
 
while ( uDiff > tol &&  n < N ) % not converged and below iterations limit
     
    % update first mode accumulator
    k = 1;
    sum_uk = u_hat_plus(n,:,K)   sum_uk - u_hat_plus(n,:,1);
     
    % update spectrum of first mode through Wiener filter of residuals
    u_hat_plus(n 1,:,k) = (f_hat_plus - sum_uk - lambda_hat(n,:)/2)./(1 Alpha(1,k)*(freqs - omega_plus(n,k)).^2);
     
    % update first omega if not held at 0
    if ~DC
        omega_plus(n 1,k) = (freqs(T/2 1:T)*(abs(u_hat_plus(n 1, T/2 1:T, k)).^2)')/sum(abs(u_hat_plus(n 1,T/2 1:T,k)).^2);
    end
     
    % update of any other mode
    for k=2:K
         
        % accumulator
        sum_uk = u_hat_plus(n 1,:,k-1)   sum_uk - u_hat_plus(n,:,k);
         
        % mode spectrum
        u_hat_plus(n 1,:,k) = (f_hat_plus - sum_uk - lambda_hat(n,:)/2)./(1 Alpha(1,k)*(freqs - omega_plus(n,k)).^2);
         
        % center frequencies
        omega_plus(n 1,k) = (freqs(T/2 1:T)*(abs(u_hat_plus(n 1, T/2 1:T, k)).^2)')/sum(abs(u_hat_plus(n 1,T/2 1:T,k)).^2);
         
    end
     
    % Dual ascent
    lambda_hat(n 1,:) = lambda_hat(n,:)   tau*(sum(u_hat_plus(n 1,:,:),3) - f_hat_plus);
     
    % loop counter
    n = n 1;
     
    % converged yet?
    uDiff = eps;
    for i=1:K
        uDiff = uDiff   1/T*(u_hat_plus(n,:,i)-u_hat_plus(n-1,:,i))*conj((u_hat_plus(n,:,i)-u_hat_plus(n-1,:,i)))';
    end
    uDiff = abs(uDiff);
     
end
 
 
%------ Postprocessing and cleanup
 
 
% discard empty space if converged early
N = min(N,n);
omega = omega_plus(1:N,:);
 
% Signal reconstruction
u_hat = zeros(T, K);
u_hat((T/2 1):T,:) = squeeze(u_hat_plus(N,(T/2 1):T,:));
u_hat((T/2 1):-1:2,:) = squeeze(conj(u_hat_plus(N,(T/2 1):T,:)));
u_hat(1,:) = conj(u_hat(end,:));
 
u = zeros(K,length(t));
 
for k = 1:K
    u(k,:)=real(ifft(ifftshift(u_hat(:,k))));
end
 
% remove mirror part
u = u(:,T/4 1:3*T/4);
 
% recompute spectrum
clear u_hat;
for k = 1:K
    u_hat(:,k)=fftshift(fft(u(k,:)))';
end
 
end

标签: 算法 VMD 信号

实例下载地址

VMD算法分解信号

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警