Adding custom wavelets to cwt

조회 수: 28 (최근 30일)
Jakob Sørensen
Jakob Sørensen 2013년 5월 11일
댓글: Tung 2024년 4월 29일
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
  댓글 수: 2
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?)
Tung
Tung 2024년 4월 29일
Hi Alexey. The link that you posted no longer works. Could you please share the new link. Thank you!

댓글을 달려면 로그인하십시오.


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 CenterFile Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by