用matlab对语音加差值噪声和脉冲噪声及其滤波处理的实验代码
时间: 2023-11-27 22:06:22 浏览: 35
下面是用 Matlab 实现语音加差值噪声和脉冲噪声及其滤波处理的实验代码:
```matlab
% 加性差值噪声
clear all; close all; clc;
[x,fs] = audioread('test.wav'); % 读取语音信号
d = adddelta(x,0.5); % 加入差值噪声
sound(d,fs); % 播放加噪后的语音信号
figure; subplot(211); plot(x); title('原始语音信号');
subplot(212); plot(d); title('加差值噪声后的语音信号');
% 滤波处理
Wp = 5000/(fs/2); Ws = 6000/(fs/2);
Rp = 1; Rs = 60; [n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn,'high');
y = filter(b,a,d); % 高通滤波
sound(y,fs); % 播放滤波后的语音信号
figure; subplot(211); plot(d); title('加差值噪声后的语音信号');
subplot(212); plot(y); title('滤波后的语音信号');
% 加性脉冲噪声
clear all; close all; clc;
[x,fs] = audioread('test.wav'); % 读取语音信号
d = imnoise(x,'salt & pepper',0.1); % 加入脉冲噪声
sound(d,fs); % 播放加噪后的语音信号
figure; subplot(211); plot(x); title('原始语音信号');
subplot(212); plot(d); title('加脉冲噪声后的语音信号');
% 滤波处理
Wp = 3000/(fs/2); Ws = 4000/(fs/2);
Rp = 1; Rs = 60; [n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn,'low');
y = filter(b,a,d); % 低通滤波
sound(y,fs); % 播放滤波后的语音信号
figure; subplot(211); plot(d); title('加脉冲噪声后的语音信号');
subplot(212); plot(y); title('滤波后的语音信号');
```
其中,`addelta` 函数用于加差值噪声,`imnoise` 函数用于加脉冲噪声,`filter` 函数用于滤波处理。这里分别对加差值噪声和加脉冲噪声的语音信号进行滤波处理,以模拟实际应用场景中的滤波处理操作。