Adding custom wavelets to cwt

31 ビュー (過去 30 日間)
Jakob Sørensen
Jakob Sørensen 2013 年 5 月 11 日
回答済み: Sen Jing 2022 年 1 月 2 日
Hi there,
Summary: How do I take a custom signal y and turn it into a wavelet for cwt?
Long version: I'm looking into analysis of otoacoustic emissions, using wavelet transformation, meaning that I need to use the cwt function in MATLAB. That is not the problem, the problem is that none of the standard wavelets are any good for otoacoustic emissions. So I'm trying to add a new custom wavlet, using wavemngr. So far, I've come up with the following code...
% Create the pattern signal
t = linspace(0, 1, 1024);
y = (1./(1+(4*(t-0.5)).^4)).*cos(20*(t-0.5));
% Create a polynomial fit of the pattern signal
[psi,tval,nc] = pat2cwav(y, 'polynomial', 10, 'continuous') ;
% Plot the pattern compared to the polynomial fit
plot(t,y,'-',tval,nc*psi,'--'),
title('Original Pattern and Adapted Wavelet (dashed line)')
save('mother', 'nc', 'psi', 'tval');
wavemngr('del','CosWave');
wavemngr('add','CosWave','cosw',4,'','mother');
This however only gives rise to an error:
>> makeWavelet
******************************************************
ERROR ...
------------------------------------------------------
wavemngr ---> Invalid Wavelet Family (Short) Name !
******************************************************
****
ERROR ...
----
wavemngr --->
Add New Wavelet FAILED !!
Invalid number of arguments !
****
I'm probably doing it all wrong, but I really don't get the documentation, so can anyone help me figure out how to get my signal y turned into a wavelet that can be used for cwt?
Best regards and have a nice weekend!
  1 件のコメント
Jakob Sørensen
Jakob Sørensen 2013 年 5 月 11 日
Note:
I also tried implementing the function value (array) into cwt directly like this:
scales = 1:32;
t = linspace(0,1,512);
MotherWave = (1./(1+(4*(t-0.5)).^4)).*cos(20*(t-0.5));
Coeffs = cwt(y, scales, MotherWave);
While this works, it seems to give an incorrect wavelet transformation, with no apparent relation to the signal.

サインインしてコメントする。

回答 (5 件)

Honglei Chen
Honglei Chen 2013 年 5 月 13 日
I think you need to define a MATLAB function for the custom wavelet and then pass it to the wavemngr. The link below has a little more details:
www.mathworks.com/help/wavelet/ug/adding-your-own-wavelets.html
There is a section talking about how to build that function.
HTH
  1 件のコメント
Alexey
Alexey 2016 年 1 月 7 日
編集済み: Alexey 2016 年 1 月 7 日
I think User-Defined-Wavelets is a much clearer tutorial than adding-your-own you mentioned (should it be removed altogether?)

サインインしてコメントする。


jan
jan 2013 年 9 月 5 日
I think you forgott one value
wavemngr('add','CosWave','cosw',1,'1','mother');
the second 1 should`t be empty. That how it worked for me even if you only have one Wavelet in your wavelet family (it can still be a happy family)
Greatings from Eindhoven Jan
  3 件のコメント
TG
TG 2015 年 2 月 27 日
編集済み: TG 2015 年 2 月 27 日
@above: The most common way to use a new wavelet to analyze a signal is
wtrans = cwt(signal,no_scales,'newwavelet','plot');
where 'newwavelet' is your newly designed wavelet.
Alexey
Alexey 2016 年 1 月 7 日
編集済み: Alexey 2016 年 1 月 7 日
@jan: your advice didn't work for me: if you look at wavemngr.m line 216, you'll see it's looking for 'no' and converts it to empty string ''. So if you supply empty string (string of length 0), you should be fine.
Note that the space character ' ' (as per wavemngr help) doesn't work for me either - it gives error
wavemngr('add', 'CosWave', 'cosw', 1, ' ', 'mother');
Index exceeds matrix dimensions.
Error in wavemngr (line 460)
k0 = index1(1);
Error in wavemngr (line 719)
wavemngr('create');
460 k0 = index1(1);
I wrote to mathworks so that they would correct the manual but didn't hear back yet.
Your advice probably works if you invoke your wavelet as 'cosw1', but I prefer to keep it without any numbers and hence I think
wavemngr('add', 'CosWave', 'cosw', 1, '', 'mother');
is more correct and the wavelet should be called afterwords with
wname = 'cosw';
Also, I kept trying different things and my wavemngr eventually got really corrupted ('del' and 'restore' and 'clear' wouldn't work). If you're in the same boat, delete
wavelets.asc
wavelets.prv
wavelets.inf
in your work directory. Then do
wavemngr('restore')

サインインしてコメントする。


Jean-Luc Bruyelle
Jean-Luc Bruyelle 2015 年 7 月 15 日
編集済み: Jean-Luc Bruyelle 2015 年 7 月 15 日
Hi
I had the same problem and it comes from the "save" step.
First, when you use "save" you have to save in a .mat file. Than , when you correctly save your pattern , I had an error message and when i opened the script of the wavemngr function and execute step by step it stopped when an other function was called because of the name of the variables that i registered in my .mat file, so I had to call xval and psi X and Y and after having changed their names my code worked.
Here is the code I suggest you, you can try and comment me if it corked fine, that the code i used.
% Create the pattern signal t = linspace(0, 1, 1024); y = (1./(1+(4*(t-0.5)).^4)).*cos(20*(t-0.5));
% Create a polynomial fit of the pattern signal [Y,X,nc] = pat2cwav(y, 'polynomial', 10, 'continuous') ;
% Plot the pattern compared to the polynomial fit plot(t,y,'-',tval,nc*Y,'--'), title('Original Pattern and Adapted Wavelet (dashed line)') save('mother.mat', 'Y', 'X');
% you dont need the nc value to be save as by convention all wavelets saved are of energy = 1 (the integral =1) and this variable is not used in cwt or wavemngr, it is only useful to pass from your pattern to the adapted pattern
wavemngr('del','CosWave');
wavemngr('add','CosWave','cosw',4,'','mother.mat');
  2 件のコメント
Alexey
Alexey 2016 年 1 月 7 日
Jean-Luc,
This looks good, just couple pointers that made it work for me:
  1. some lines got squished together - please use the code formatting button on top
  2. tval is not defined, X should be used instead
  3. wavemngr is missing one argument - B (1x2 support interval)
corrected code that works for me (the 'del' statement is not necessary for a clean machine, but if you have CosWave defined, then it's good to delete it):
clear; clc; format compact
% Create the pattern signal
t = linspace(0, 1, 1024);
y = (1./(1+(4*(t-0.5)).^4)).*cos(20*(t-0.5));
% Create a polynomial fit of the pattern signal
[Y,X,nc] = pat2cwav(y, 'polynomial', 10, 'continuous') ;
% Plot the pattern compared to the polynomial fit
plot(t,y,'-',X,nc*Y,'--'),
title('Original Pattern and Adapted Wavelet (dashed line)')
save('mother.mat', 'Y', 'X');
% you dont need the nc value to be save as by convention all wavelets saved are of energy = 1 (the integral =1) and this variable is not used in cwt or wavemngr, it is only useful to pass from your pattern to the adapted pattern
wavemngr('del','CosWave');
wavemngr('add','CosWave','cosw',4,'','mother.mat',[0 1]);
Bahar Mohseni
Bahar Mohseni 2016 年 6 月 11 日
Hi Alexey,
I am trying to add a new wavelet to the wavemngr and I use the corrected code which worked for you but I still get these errors. Can you please help me with this?
Index exceeds matrix dimensions.
Error in wavemngr (line 460)
k0 = index1(1);
Error in wavemngr (line 719)
wavemngr('create');

サインインしてコメントする。


amin
amin 2017 年 12 月 18 日
Hello I used this code as an example for defining a new mother wavelet. but it does not work with wpdec(input,1,'cosw','shannon') how does the new wavelet should be used? following you can see the error when I use it: ERROR ... ----------------------------------------------- wfilters ---> The wavelet cosw is not valid!
Kind Regards Amin

Sen Jing
Sen Jing 2022 年 1 月 2 日
I use th following code,because in the new version matlab, the older version cwt is abandon,and they constraint the wname to 'amore', 'morlet','morse'
scales = 1:32;
t = linspace(0,1,512);
MotherWave = (1./(1+(4*(t-0.5)).^4)).*cos(20*(t-0.5));
Coeffs = wavelet.internel.cwt(y, scales, MotherWave);

カテゴリ

Help Center および File ExchangeContinuous Wavelet Transforms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by