% 小波变换用于奇异检测
clc;clear;
% 下载信号
load freqbrk;
s=freqbrk; % s 原始信号
% 原始信号长度
n=length(s);
% 构造小波函数
delta=-2; % delta 小波变换的尺度
A=-2/sqrt(pi); % 幅度
delta_t=2^(delta); % 尺度
N=20; % N 高斯函数的长度
for index_x=1:N;
x=index_x-(N+1)/2;
phi_x(index_x)=A*(x/delta_t.^(3/2)).*exp(-(x.*x)/(delta_t^2));
end;
phi_x=phi_x/norm(phi_x); % 能量归一化
% 对信号做卷积
g=conv(s,phi_x); % 卷积
g=wkeep(g,n); % 保持信号长度
% 模极大值
maxima_t=abs(g); % 取模
maxima=zeros(n,1); % 模极大值数组
for i=2:n-1;
if ((maxima_t(i)>=maxima_t(i-1)) & (maxima_t(i)>=maxima_t(i+1)))
maxima(i)=maxima_t(i);
end
end;
% 去除小的模极大值
maxima=maxima/max(maxima);
threshold=0.6; % 阈值
for i=2:n-1;
if (maxima(i)<threshold)
maxima(i)=0;
end
end;
% 显示结果
figure(1);
subplot(2,1,1);
plot(0:n-1,s); % 原始信号
xlabel('离散时间');
ylabel('信号幅值');
title('原始信号')
subplot(2,1,2);
hold on;
plot(0:n-1,maxima); % 信号经小波变换后的模极大值
xlabel('离散时间');
ylabel('模极大值');
评论0