当前位置:   article > 正文

将时间序列转成图像——小波变换方法 Matlab实现_时序数据转化为电气图像matlab

时序数据转化为电气图像matlab

目录

1 方法

2 Matlab代码实现

3 结果


【若觉文章质量良好且有用,请别忘了点赞收藏加关注,这将是我继续分享的动力,万分感谢!】

其他:

1.时间序列转二维图像方法及其应用研究综述_vm-1215的博客-CSDN博客

2.将时间序列转成图像——短时傅里叶方法 Matlab实现_vm-1215的博客-CSDN博客

3.将时间序列转成图像——希尔伯特-黄变换方法 Matlab实现_vm-1215的博客-CSDN博客

1 方法

小波变换(Wavelet Transform, WT)是1984年由Morlet和Grossman提出的概念,该方法承袭了短时间窗变换的局部化思想,且克服了时间-窗口大小不变的缺陷,提供了一个窗口宽度可随频率变化而变宽变窄的时频窗,从而充分突出信号的某些特征。其基本思想是:先构造一个有限长或快速衰减的母小波,然后通过缩放和平移生成多个子小波,再叠加以匹配输入信号。将其缩放尺度和平移参数对应频率和时间参数,最终得到信号的时频图。

Wf(a,b)=<f,ψa,b>=1|a|+f(t)ψ(tba)dtWf(a,b)=<f,ψa,b>=1|a|+f(t)ψ(tba)dt

其中, ψa,bψa,b​ 为母小波函数(Morlet、Ricker 等), aa​为尺度給数,bb​为平移給数。 根据小波变换的定义, 给定时变信号f(t)f(t)​, 其编码步骤如下:

  1. 确定参数:信号长度flenflen​, 采样频率sampleratesamplerate​, 母小波函数, 中心频率滑动步长cenfrestepcenfrestep​;
  2. 计算最大中心频率cenfremax=samplerate2cenfremax=samplerate2​,设置当前中心频率cenfrenow=1cenfrenow=1​,初始化时频矩阵SS​;
  3. 根据中心频率和小波函数,构造小波曲线,再与原信号卷积,得到当前频率的时间分布向量,更新时频矩阵;
  4. 判断当前中心频率是否大于最大中心频率,若是,输出时频矩阵SS​;否则,更新当前频率cenfrenow=cenfrenow+cenfrestepcenfrenow=cenfrenow+cenfrestep​,然后跳回步骤2。

小波变换相较于短时傅里叶变换,具有较好的时频分辨率自适应能力,更能突出实际信号的局部特征,即高频处采用低频率分辨率和高时间分辨率,低频处采用高频率分辨率和低时间分辨率。因而,小波变换在信号处理、语音处理、图像处理等领域得到广泛应用。

2 Matlab代码实现

  1. clear, close all
  2. %% initialize parameters
  3. samplerate=500; % in Hz
  4. fstep=1; % frequency step for wavelet
  5. %% generate simulated signals with step changes in frequency
  6. data = csvread('3_1_link6_28_5_30min.csv'); % input the signal from the Excle
  7. data = data'; % change the signal from column to row
  8. N = length(data); % calculate the length of the data
  9. taxis = [1:N]/samplerate; % time axis for whole data length
  10. figure,
  11. plot(taxis,data),xlim([taxis(1) taxis(end)])
  12. xlabel('Time (s)')
  13. %% Time-frequency analysis (CWT, morlet wavelet)
  14. spec = tfa_morlet(data, samplerate, 1, 250, fstep);
  15. faxis=[1:fstep:250];
  16. Mag=abs(spec); % get spectrum magnitude
  17. im = figure('color',[1 1 1]);
  18. imagesc(taxis,faxis,Mag) % plot spectrogram as an image
  19. colorbar
  20. axis([taxis(1) taxis(end) faxis(1) faxis(end)])
  21. xlabel('Time (s)')
  22. ylabel('Frequency (Hz)')
  23. title('Time-frequency analysis (CWT)')
  24. saveas(im,'CWT_1.bmp')
  25. function TFmap = tfa_morlet(td, fs, fmin, fmax, fstep)
  26. TFmap = [];
  27. for fc=fmin:fstep:fmax
  28. MW = MorletWavelet(fc/fs); % calculate the Morlet Wavelet by giving the central freqency
  29. cr = conv(td, MW, 'same'); % convolution
  30. TFmap = [TFmap; abs(cr)];
  31. end
  32. function MW = MorletWavelet(fc)
  33. F_RATIO = 7; % frequency ratio (number of cycles): fc/sigma_f, should be greater than 5
  34. Zalpha2 = 3.3; % value of Z_alpha/2, when alpha=0.001
  35. sigma_f = fc/F_RATIO;
  36. sigma_t = 1/(2*pi*sigma_f);
  37. A = 1/sqrt(sigma_t*sqrt(pi));
  38. max_t = ceil(Zalpha2 * sigma_t);
  39. t = -max_t:max_t;
  40. %MW = A * exp((-t.^2)/(2*sigma_t^2)) .* exp(2i*pi*fc*t);
  41. v1 = 1/(-2*sigma_t^2);
  42. v2 = 2i*pi*fc;
  43. MW = A * exp(t.*(t.*v1+v2));

3 结果

【若觉文章质量良好且有用,请别忘了点赞收藏加关注,这将是我继续分享的动力,万分感谢!】​

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/284601
推荐阅读
相关标签
  

闽ICP备14008679号