matlab 的wavedec函数源程序
时间: 2023-08-22 10:10:13 浏览: 171
`wavedec` 函数是 Matlab 中用于进行小波分解的函数之一,以下是它的源程序:
```matlab
function [C,L] = wavedec(X,N,Lo_D,Hi_D)
%WAVEDEC Multilevel 1-D wavelet decomposition.
% WAVEDEC performs a multilevel 1-D wavelet decomposition
% of the signal X at level N, using the wavelet filters
% Lo_D and Hi_D (called the decomposition filters or the
% analysis filters) obtained from the wavelet wname.
%
% C = WAVEDEC(X,N,'wname') returns the wavelet decomposition
% of the signal X at level N, using 'wname'. 'wname' is a string
% containing the name of the wavelet (see WFILTERS).
% C is a vector containing the detailed coefficients (called
% the wavelet coefficients or the detail coefficients) of the
% decomposition. Length(C) = length(X) so that the approximation
% coefficients (see WAPPDEC) can be obtained using the command
% APPCOEF(C,L,'wname',N).
%
% [C,L] = WAVEDEC(...) returns the vector of wavelet
% coefficients C and the bookkeeping matrix L which contains
% the lengths of the successive subbands and the position of
% the first coefficient of each subband in C. Such a bookkeeping
% matrix is useful when you want to manipulate wavelet
% coefficients.
%
% C = WAVEDEC(X,N,Lo_D,Hi_D) returns the wavelet decomposition
% of the signal X at level N, using Lo_D and Hi_D. Lo_D and Hi_D
% are the decomposition filters.
%
% See also APPCOEF, DETCOEF, WRcoef, UPWLEV, WAVEREC.
% M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-Jun-95.
% Last Revision: 15-Sep-99.
% Check arguments for Extension and Shift.
%---------------------------------------------------------%
nbIn = nargin;
shift = 0;
if ischar(N)
[Lo_D,Hi_D] = wfilters(N,'d');
N = varargin{1};
nbIn = nbIn-1;
elseif ischar(Lo_D)
[Lo_D,Hi_D] = wfilters(Lo_D,'d');
shift = nargin-2;
nbIn = nbIn-2;
end
if nbIn<2 , error(message('Wavelet:wavelet:Invalid_ArgNum')); end
if ~isnumeric(N) || N<0 || fix(N)~=N
error(message('Wavelet:wavelet:Invalid_WavLevel'));
end
% Initialization.
%---------------------------------------------------------%
if rem(size(Lo_D,2),2) , Lo_D = Lo_D(:)' ; end
if rem(size(Hi_D,2),2) , Hi_D = Hi_D(:)' ; end
X = X(:)';
cA = X;
sizes = zeros(N+1,length(cA));
sizes(N+1,:) = length(cA);
Lo_D = Lo_D(:)';
Hi_D = Hi_D(:)';
for k = 1:N
[cA,cD] = dwtImpl(cA,Lo_D,Hi_D);
sizes(N+1-k,:) = length(cA);
end
C = [cA , cD];
L = diff([0 sizes(:)'-shift]);
%---------------------------------------------------------%
function [app,detail] = dwtImpl(signal,F1,F2)
% Compute sizes.
lf = length(F1);
lx = length(signal);
lx = lx + rem(lf-mod(lx,lf),lf);
ly = lx/lf;
signal(lx) = 0;
% Compute coefficients of low-pass and high-pass filters.
F1 = F1(:)';
F2 = F2(:)';
F1 = F1(:,ones(1,ly));
F2 = F2(:,ones(1,ly));
signal = signal(:);
signal = signal(ones(1,ly),:);
% Filtering.
app = sum(signal .* F1, 1);
detail = sum(signal .* F2, 1);
% Upsampling.
app = app(:)';
detail = detail(:)';
```
该函数的输入参数包括:信号 X、小波分解级数 N、小波分解滤波器的低通滤波器 Lo_D 和高通滤波器 Hi_D。输出参数包括:小波分解系数 C 和分解结构 L。
在 `wavedec` 函数中,首先会对输入参数进行检查和初始化,然后根据小波分解级数 N 和滤波器 Lo_D 和 Hi_D 对信号进行小波分解,得到小波分解系数 C 和分解结构 L。最后将 C 和 L 输出。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)