dlcwt
Description
Examples
Deep Learning Continuous Wavelet Transform of ECG Signal
Load the ECG signal. The sampling frequency of the data is 180 hertz. Save the signal as a dlarray
in "CBT"
format.
load wecg Fs = 180; sig = dlarray(reshape(wecg,1,1,[]),"CBT");
Create a CWT filter bank that is compatible with the signal. Specify periodic boundary conditions.
fb = cwtfilterbank(SignalLength=length(sig),Boundary="periodic");
Use the wt
object function to obtain the CWT coefficients of wecg
. Also obtain the scaling coefficients. Concatenate the coefficients.
[cfsFB,~,~,scalcfs] = wt(fb,wecg);
allCFS = [cfsFB ; scalcfs];
whos allCFS
Name Size Bytes Class Attributes allCFS 82x2048 2686976 double complex
Use the cwtfilters2array
function to convert the filter bank to a reduced-weight tensor suitable for deep learning. Include the lowpass (scaling) filter in the tensor.
[psifvec,filteridx] = cwtfilters2array(fb,IncludeLowpass=true);
Obtain the deep learning CWT of the signal.
cfsD = dlcwt(sig,psifvec,filteridx); dims(cfsD)
ans = 'SCBT'
By default, the output is a dlarray
object in "SCBT"
format. The spatial dimension corresponds to frequency. Convert the output to a numeric array. Permute the dimensions of the output to correspond with "STCB"
format. The result will be a 2-D matrix because there is only one channel and one batch.
cfs = extractdata(cfsD);
cfs = permute(cfs,[1 4 2 3]);
whos cfs
Name Size Bytes Class Attributes cfs 82x2048 2686976 double complex
Confirm the CWT and deep learning CWT of the signal are equal.
max(abs(cfs(:)-allCFS(:)))
ans = 1.0235e-09
Deep Learning Continuous Wavelet Transform of Multisignal
Load the Espiga3 EEG dataset. The data consists of 23 channels of EEG sampled at 200 Hz. There are 995 samples in each channel. Save the multisignal as a dlarray
, specifying the dimensions in order. dlarray
permutes the array dimensions to the "CBT"
shape expected by a deep learning network.
load Espiga3 Fs = 200; [N,nch] = size(Espiga3); x = dlarray(Espiga3,"TCB"); whos Espiga3 x
Name Size Bytes Class Attributes Espiga3 995x23 183080 double x 23x1x995 183110 dlarray
Create a CWT filter bank that is compatible with the signal. Specify periodic boundary conditions. Then use the cwtfilters2array
function to convert the filter bank to a reduced-weight tensor suitable for deep learning.
fb = cwtfilterbank(SignalLength=N,Boundary="periodic");
[psifvec,filteridx] = cwtfilters2array(fb);
Obtain the deep learning CWT of the multisignal.
cfsD = dlcwt(x,psifvec,filteridx); dims(cfsD)
ans = 'SCBT'
By default, the output is a dlarray
object in "SCBT"
format. The spatial dimension corresponds to frequency. Convert the output to a numeric array. Permute the dimensions of the output to correspond with "STCB"
format. The result will be a 3-D array because there is only one batch.
cfs = extractdata(cfsD);
cfs = permute(cfs,[1 4 2 3]);
whos cfs
Name Size Bytes Class Attributes cfs 71x995x23 25997360 double complex
Obtain the center frequencies from the original filter bank. Display the scalogram of a channel.
frq = centerFrequencies(fb); channel = 4; cfsChannel = cfs(:,:,channel); tms = (0:N-1)/Fs; surface(tms,frq,abs(cfsChannel)) set(gca,"yscale","log") axis tight shading flat title("Scalogram") xlabel("Time (s)") ylabel("Frequency (Hz)")
Input Arguments
x
— Input data
dlarray
object | numeric array
Input data, specified as a real-valued unformatted dlarray
object,
a formatted dlarray
in "CBT"
format, or a numeric
array. If x
is an unformatted dlarray
or a numeric
array, you must specify the 'DataFormat'
as some permutation of
"CBT"
.
Data Types: single
| double
psifvec
— CWT filter bank
numeric array
CWT filter bank, specified as a 1-by-1-by-Nr tensor, where
Nr is the number of weights in the reduced-weight CWT filter bank.
Use cwtfilters2array
to obtain psifvec
.
You can use array2cwtfilters
to reconstruct the 2-D CWT filter bank from the outputs
of cwtfilters2array
.
Data Types: double
filteridx
— Bookkeeping matrix
matrix
Bookkeeping matrix, specified as a matrix. The dlcwt
function
uses filteridx
to index into the data x
and
filter bank psifvec
in order to compute the CWT. Use cwtfilters2array
to obtain filteridx
.
Data Types: uint32
fmt
— Input data format
character vector | string scalar
Input data format of x
, specified as some permutation of
"CBT"
. This argument is invalid if x
is a
formatted dlarray
.
Each character in this argument must be one of these labels:
"C"
— Channel"B"
— Batch"T"
— Time
The dlcwt
function accepts any permutation of
"CBT"
. Each element of the argument labels the matching dimension
of x
.
Example: w = dlcwt(x,psifvec,filteridx,DataFormat="BCT")
specifies
the data format of the unformatted dlarray
object as
"BCT"
.
Data Types: char
| string
Output Arguments
cfs
— Continuous wavelet transform
formatted dlarray
object | unformatted dlarray
object
Continuous wavelet transform of x
, returned as a
dlarray
object.
If
x
is a formatteddlarray
object,cfs
is in"SCBT"
format. The spatial dimension corresponds to scale, or equivalently the center frequency of the wavelet bandpass filters. The channel, batch, and time dimensions correspond to the channel, batch, and time dimensions ofx
.If
x
is an unformatteddlarray
object or numeric array,cfs
is an unformatteddlarray
object. The dimension order incfs
is"SCBT"
.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The dlcwt
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2022b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)