使用小波变换的电能质量扰动时间定位,观测时间长度取0.6s,构造理想的暂降信号波形函数,u(t) =u1(t) + u2(t) + u3(t)其中: u1(t)= A1sin(w1(t)) 0<t≤0.2,u2(t) = A2sin(w2(t))0.2 <t≤0.3, u3(t) = A3sin(w3(t)) 0.3<t≤0.5 令A1=A2= 8500V,A2=5200V 1.步长取0.001,仿真出理想的暂降波形,并对其进行小波分解,根据信号奇异性表现,计算出暂降持续时间。 2.混合上各种噪声信号,对小波信号降噪。分三种情况进行,看看哪种效果好:D不调整闯值:2)对各层噪声分别进行调整:3)对第一层系数的层噪声进行一次估计调整,请给我Matlab程序
时间: 2024-03-06 19:46:23 浏览: 13
以下是基于Matlab实现的程序,包含了构造暂降信号、小波分解、噪声混合、小波信号降噪等步骤:
构造暂降信号:
```matlab
% 构造暂降信号
A1 = 8500; w1 = 100*pi;
A2 = 5200; w2 = 150*pi;
A3 = 8500; w3 = 200*pi;
t = 0:0.001:0.6;
u1 = A1*sin(w1*t).*(t<=0.2);
u2 = A2*sin(w2*t).*(t>0.2 & t<=0.3);
u3 = A3*sin(w3*t).*(t>0.3 & t<=0.5);
u = u1 + u2 + u3;
```
小波分解:
```matlab
% 小波分解
level = 5;
[C, L] = wavedec(u, level, 'db4');
```
计算暂降持续时间:
```matlab
% 计算暂降持续时间
cA = appcoef(C, L, 'db4', level);
threshold = 5*std(cA);
duration = sum(abs(cA)>threshold)*0.001;
```
噪声混合:
```matlab
% 噪声混合
u_noisy = awgn(u, 10, 'measured');
```
小波信号降噪:
```matlab
% 小波信号降噪
% 不调整阈值
[C_noisy, L_noisy] = wavedec(u_noisy, level, 'db4');
C_denoised = wthresh(C_noisy, 'h', threshold);
u_denoised = waverec(C_denoised, L_noisy, 'db4');
% 对各层噪声分别进行调整
[C_noisy, L_noisy] = wavedec(u_noisy, level, 'db4');
C_denoised = C_noisy;
for i = 1:level
startIdx = L_noisy(i)+1;
endIdx = L_noisy(i+1);
cA = C_denoised(startIdx:endIdx);
threshold = 5*std(cA);
C_denoised(startIdx:endIdx) = wthresh(cA, 'h', threshold);
end
u_denoised2 = waverec(C_denoised, L_noisy, 'db4');
% 对第一层系数的层噪声进行一次估计调整
[C_noisy, L_noisy] = wavedec(u_noisy, level, 'db4');
cA1 = appcoef(C_noisy, L_noisy, 'db4', 1);
threshold = 5*std(cA1);
C_denoised = wthresh(C_noisy, 'h', threshold);
u_denoised3 = waverec(C_denoised, L_noisy, 'db4');
```
完整程序如下:
```matlab
% 构造暂降信号
A1 = 8500; w1 = 100*pi;
A2 = 5200; w2 = 150*pi;
A3 = 8500; w3 = 200*pi;
t = 0:0.001:0.6;
u1 = A1*sin(w1*t).*(t<=0.2);
u2 = A2*sin(w2*t).*(t>0.2 & t<=0.3);
u3 = A3*sin(w3*t).*(t>0.3 & t<=0.5);
u = u1 + u2 + u3;
% 小波分解
level = 5;
[C, L] = wavedec(u, level, 'db4');
% 计算暂降持续时间
cA = appcoef(C, L, 'db4', level);
threshold = 5*std(cA);
duration = sum(abs(cA)>threshold)*0.001;
% 噪声混合
u_noisy = awgn(u, 10, 'measured');
% 小波信号降噪
% 不调整阈值
[C_noisy, L_noisy] = wavedec(u_noisy, level, 'db4');
C_denoised = wthresh(C_noisy, 'h', threshold);
u_denoised = waverec(C_denoised, L_noisy, 'db4');
% 对各层噪声分别进行调整
[C_noisy, L_noisy] = wavedec(u_noisy, level, 'db4');
C_denoised = C_noisy;
for i = 1:level
startIdx = L_noisy(i)+1;
endIdx = L_noisy(i+1);
cA = C_denoised(startIdx:endIdx);
threshold = 5*std(cA);
C_denoised(startIdx:endIdx) = wthresh(cA, 'h', threshold);
end
u_denoised2 = waverec(C_denoised, L_noisy, 'db4');
% 对第一层系数的层噪声进行一次估计调整
[C_noisy, L_noisy] = wavedec(u_noisy, level, 'db4');
cA1 = appcoef(C_noisy, L_noisy, 'db4', 1);
threshold = 5*std(cA1);
C_denoised = wthresh(C_noisy, 'h', threshold);
u_denoised3 = waverec(C_denoised, L_noisy, 'db4');
% 画图
figure;
subplot(2,2,1); plot(t, u); title('原始信号');
subplot(2,2,2); plot(t, u_noisy); title('加噪声信号');
subplot(2,2,3); plot(t, u_denoised); title('降噪信号1');
subplot(2,2,4); plot(t, u_denoised2); title('降噪信号2');
```
注意,本程序中小波变换采用的是db4小波基,噪声强度设置为10dB,可以根据具体需求进行调整。此外,程序中对阈值的设置也很关键,需要根据实际情况进行调整。