Using Wavelet Time-Frequency Analyzer App

尝试此示例 复制代码 复制命令

此示例演示如何使用小波时频分析器应用程序可视化 1-D 信号的小波图。小波图是连续小波变换 (CWT) 的绝对值。您可以调整在 CWT 中使用的小波参数、每个八度的音调以及频率限制。您可以比较多个小波图并将小波图导出到您的工作区。您还可以通过生成一个 MATLAB 脚本在您的工作区中重新创建小波图。

Import Data

将“wecg”信号加载到MATLAB工作区。采样频率为180 Hz。

load wecg
Fs = 180;
 

Visualize Scalogram

在打开小波时频分析器后,点击“导入信号”按钮。会弹出一个窗口,显示该应用可以处理的所有工作区变量的列表。选择"wecg"信号并点击"导入"。在短暂的一次性初始化后,导入的信号的名称和类型将显示在“信号”窗格中。该应用程序在“Scalogram-wecg”图中显示小波时频图。应用程序使用分析莫尔斯(3, 60)小波和默认设置的cwt函数生成小波时频图。影响锥显示了在小波时频图中受边缘效应影响的区域。你应该将虚线白线以外的阴影区域视为可疑,因为可能存在边缘效应。要了解有关影响锥的更多信息,请参阅边缘效应和影响锥。

您可以通过在“首选项”▼菜单中设置选项来隐藏或显示影响锥边界线,或者在影响锥区域上设置阴影。如果信号是复值的,则还可以选择将正向(逆时针)和负向(顺时针)分量显示为单独的或连接的小波时频图。在“首选项”▼菜单中选择的选项在MATLAB会话之间持久存在。

默认情况下,因为信号不是时间表,该应用程序以循环/样本的频率绘制频率,并使用样本索引作为时间轴的基础。如果导入的信号是时间表,则该应用程序将小波时频图绘制为频率的函数(以赫兹为单位),并使用时间表的行时间作为时间轴的基础。

在“分析器”选项卡上,选择“采样率”单选按钮。小波时频图的坐标轴标签将使用默认采样率1赫兹更新。为了使坐标轴标签适用于"wecg"信号,请在“采样率”字段中应用值180。您无法修改时间表的采样率。

afterImport.png

Modify Wavelet Parameters

要访问创建小波图的连续小波变换(CWT)参数,请单击“Scalogram”选项卡。这些参数对应于cwt函数的输入参数。参数设置为默认值。由于您设置了采样率,所以最小和最大频率限制以赫兹为单位。默认频率限制取决于小波、信号长度、采样率和每个八度的声音数。有关更多信息,请参阅cwtfreqbounds。

scalogramTabShorter.png

为了使用Morse(40, 60)小波获取尺度图,首先在“Symmetry”文本框中更改Morse对称参数为40。然后,为了输入新值,可以按下键盘上的“Enter”键或在文本框之外的任何地方单击鼠标。

您可以随时通过单击“Reset Parameters”将CWT参数重置为其默认值。重置参数后,将启用“Compute Scalogram”按钮。

注意:为了防止无效设置,应用程序会立即验证您更改的任何参数。如果输入无效值,应用程序将自动用有效值替换。应用程序将以下值视为无效:

新值可能不是所需的值。为避免意外结果,应确保输入的任何值始终导致有效的设置。有关更多信息,请参阅示例“Adjust Morse Wavelet Parameters”。

setSymTo40.png

要应用您的更改并可视化新的频谱图,请点击“计算频谱图”按钮。

scalogramAt40.png

Compare Scalograms

To compare the current scalogram with one obtained using the bump wavelet, first click the Duplicate button on the Analyzer tab. A second signal, wecgCopy, appears in the Signals pane. The scalogram of the duplicate appears in the Scalogram-wecgCopy plot. Then in the Scalogram tab, select bump from the Wavelet dropdown menu. Observe the Morse wavelet parameters are now disabled, and the frequency limits are updated. To create the scalogram with the bump wavelet, click Compute Scalogram. To compare with the first scalogram, select wecg in the Signals pane.

bumpScalo2.png

Export Results

You can export a structure array to your workspace that contains the CWT of the selected signal. You can also generate a MATLAB® script to recreate the scalogram in your workspace.

Export Structure

To export the CWT of wecgCopy, select that signal in the Signals pane. Then select Export Scalogram from the Export ▼ menu to create the structure array wecgCopy_scalogram in your workspace. The structure array has three fields:

  • coefficients — CWT coefficients

  • frequencyVector — Scale-to-frequency conversions

  • timeVector — Time vector

You can use the field values to visualize the scalogram in a new figure by executing these commands:

figure

pcolor(wecgCopy_scalogram.timeVector, ...
    wecgCopy_scalogram.frequencyVector, ...
    abs(wecgCopy_scalogram.coefficients))
shading flat
set(gca,"yscale","log")
title("Scalogram")
xlabel("Time (s)")
ylabel("Frequency (Hz)")
Generate Script

To generate a script that recreates the scalogram of the wecg signal in your workspace, select the wecg signal in the Signals pane. Then select Generate MATLAB Script from the Export ▼ menu. The app generates the script using the name of the signal you selected in the Signals pane. An untitled script opens in your MATLAB Editor with the following executable code.

 Get 

%Parameters
sampleRate = 180;
waveletParameters = [40,60];

%Compute time vector
t = 0:1/sampleRate:(length(wecg)*1/sampleRate)-1/sampleRate;

%Compute CWT
%If necessary, substitute workspace variable name for wecg as first input to cwt() function in code below
%Run the function call below without output arguments to plot the results
[waveletTransform,frequency] = cwt(wecg, sampleRate,...
    WaveletParameters = waveletParameters);
scalogram = abs(waveletTransform);

Save and execute the script. You can use the workspace variables scalogramt, and frequency to visualize the scalogram.

 Get 

subplot(2,1,1)
pcolor(t,frequency,scalogram)
shading flat
set(gca,"yscale","log")
title("Scalogram")
ylabel("Frequency (Hz)")
xlabel("Time (s)")
subplot(2,1,2)
plot(t,wecg)
axis tight
title("Signal")
xlabel("Time (s)")

Figure contains 2 axes objects. Axes object 1 with title Scalogram, xlabel Time (s), ylabel Frequency (Hz) contains an object of type surface. Axes object 2 with title Signal, xlabel Time (s) contains an object of type line.

See Also

Apps

Functions

Related Topics

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

___Y1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值