%% 读取信号并观察采样频率
[highFreqNoise, Fs_noise] = audioread('highFrequencyNoise.wav');
[voicePlusNoise, Fs_voice] = audioread('voiceWithHighFrequencyNoise.wav');
% 绘制信号
t_noise = (0:length(highFreqNoise)-1)/Fs_noise;
t_voice = (0:length(voicePlusNoise)-1)/Fs_voice;
figure; % 创建新图形窗口
subplot(2,1,1);
plot(t_noise, highFreqNoise);
title('高频噪声信号');
xlabel('时间t');
ylabel('幅值');
% 高频噪声信号的频谱图
Y_noise = fft(highFreqNoise);
P2_noise = abs(Y_noise/length(highFreqNoise));
P1_noise = P2_noise(1:length(highFreqNoise)/2+1);
f_noise = Fs_noise*(0:(length(highFreqNoise)/2))/length(highFreqNoise);
subplot(2,1,2);
plot(f_noise, P1_noise);
title('高频噪声信号频谱');
xlabel('频率(Hz)');
ylabel('幅度');
figure; % 创建新图形窗口
subplot(2,1,1);
plot(t_voice, voicePlusNoise);
title('高频噪声+人声');
xlabel('时间t');
ylabel('幅值');
% 高频噪声信号+人声的频谱图
Y_noise = fft(voicePlusNoise);
P4_noise = abs(Y_noise/length(voicePlusNoise));
P3_noise = P4_noise(1:length(voicePlusNoise)/2+1);
f_noise = Fs_noise*(0:(length(voicePlusNoise)/2))/length(voicePlusNoise);
subplot(2,1,2);
plot(f_noise, P3_noise);
title('高频噪声信号+人声频谱');
xlabel('频率(Hz)');
ylabel('幅度');
%% 信号的运算
% 假设已经有了两个信号 highFreqNoise 和 voicePlusNoise,以及它们的采样频率 Fs_noise 和 Fs_voice
% 这里我们使用之前的代码段中定义的操作
% 反褶(翻转)操作
flippedSignal = flipud(voicePlusNoise);
t_flipped = (0:length(flippedSignal)-1)/Fs_voice; % 更新时间向量
% 平移(例如延迟0.5秒)
delay = 0.5;
shiftedSignal = circshift(voicePlusNoise, round(Fs_voice*delay));
t_shifted = (0:length(shiftedSignal)-1)/Fs_voice; % 更新时间向量
% 相加
% 确保两个信号长度一致
minLength = min(length(highFreqNoise), length(voicePlusNoise));
highFreqNoise1 = highFreqNoise(1:minLength);
voicePlusNoise1 = voicePlusNoise(1:minLength);
addedSignal = highFreqNoise1 + voicePlusNoise1;
% 由于修改了信号长度,需要重新计算 t_voice
t_voice = (0:minLength-1)/Fs_voice;
% 相乘
multipliedSignal = highFreqNoise1 .* voicePlusNoise1;
t_multiplied = (0:length(multipliedSignal)-1)/Fs_voice; % 更新时间向量
% 绘制这些操作的结果
figure; % 创建新图形窗口
subplot(4,1,1);
plot(t_flipped, flippedSignal);
title('反褶');
xlabel('Time (seconds)');
ylabel('Amplitude');
subplot(4,1,2);
plot(t_shifted, shiftedSignal);
title('平移');
xlabel('Time (seconds)');
ylabel('Amplitude');
subplot(4,1,3);
plot(t_voice, addedSignal);
title('相加');
xlabel('Time (seconds)');
ylabel('Amplitude');
subplot(4,1,4);
plot(t_multiplied, multipliedSignal);
title('相乘');
xlabel('Time (seconds)');
ylabel('Amplitude');
% 创建新图形窗口
figure;
% 反褶信号的频谱图
Y_flipped = fft(flippedSignal);
P2_flipped = abs(Y_flipped/length(flippedSignal));
P1_flipped = P2_flipped(1:length(flippedSignal)/2+1);
f_flipped = Fs_voice*(0:(length(flippedSignal)/2))/length(flippedSignal);
subplot(4,1,1);
plot(f_flipped, P1_flipped);
title('反褶的频谱');
xlabel('Frequency (Hz)');
ylabel('|P1(f)|');
% 平移信号的频谱图
Y_shifted = fft(shiftedSignal);
P2_shifted = abs(Y_shifted/length(shiftedSignal));
P1_shifted = P2_shifted(1:length(shiftedSignal)/2+1);
f_shifted = Fs_voice*(0:(length(shiftedSignal)/2))/length(shiftedSignal);
subplot(4,1,2);
plot(f_shifted, P1_shifted);
title('平移的频谱');
xlabel('Frequency (Hz)');
ylabel('|P1(f)|');
% 相加信号的频谱图
Y_added = fft(addedSignal);
P2_added = abs(Y_added/length(addedSignal));
P1_added = P2_added(1:length(addedSignal)/2+1);
f_added = Fs_voice*(0:(length(addedSignal)/2))/length(addedSignal);
subplot(4,1,3);
plot(f_added, P1_added);
title('相加的频谱');
xlabel('Frequency (Hz)');
ylabel('|P1(f)|');
% 相乘信号的频谱图
Y_multiplied = fft(multipliedSignal);
P2_multiplied = abs(Y_multiplied/length(multipliedSignal));
P1_multiplied = P2_multiplied(1:length(multipliedSignal)/2+1);
f_multiplied = Fs_voice*(0:(length(multipliedSignal)/2))/length(multipliedSignal);
subplot(4,1,4);
plot(f_multiplied, P1_multiplied);
title('相乘的频谱');
xlabel('Frequency (Hz)');
ylabel('|P1(f)|');
%% 傅里叶级数合成
% % 例:生成一个简单的周期信号
% f_synthetic = 2000; % 以 2000 Hz 为例
% syntheticSignal = sin(2*pi*f_synthetic*t_noise);
%
% % 傅里叶变换
% Y_synthetic = fft(syntheticSignal);
% P2_synthetic = abs(Y_synthetic/length(syntheticSignal));
% P1_synthetic = P2_synthetic(1:length(syntheticSignal)/2+1);
% f_synthetic = Fs_noise*(0:(length(syntheticSignal)/2))/length(syntheticSignal);
% figure; % 创建新图形窗口
% plot(f_synthetic, P1_synthetic);
% title('傅里叶级数合成');
% xlabel('Frequency (Hz)');
% ylabel('|P1(f)|');
%% 设计滤波器并去噪
% 设计低通滤波器
% 指定截止频率
cutoff_freq = 1000; % 以 1000 Hz 为例,根据需要调整
order = 20; % 滤波器阶数,可以根据需要调整
% 设计滤波器
lpFilt = designfilt('lowpassfir', 'FilterOrder', order, ...
'CutoffFrequency', cutoff_freq, ...
'SampleRate', Fs_voice);
% 应用滤波器
filtered_voice_lp = filter(lpFilt, voicePlusNoise);
% 绘制去噪后的信号
t_filtered_lp = (0:length(filtered_voice_lp)-1)/Fs_voice;
figure;
subplot(2,1,1);
plot(t_filtered_lp, filtered_voice_lp);
title('经过低通滤波器的信号时域谱');
xlabel('Time (seconds)');
ylabel('Amplitude');
% 对滤波后的信号进行快速傅里叶变换
Y_filtered_voice_lp = fft(filtered_voice_lp);
L = length(filtered_voice_lp); % 信号的长度
% 计算双边频谱 P2 和单边频谱 P1
P2 = abs(Y_filtered_voice_lp/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% 定义频率轴
f = Fs_voice*(0:(L/2))/L;
% 绘制频谱图
subplot(2,1,2);
plot(f, P1)
title('经过低通滤波器的信号频域谱')
xlabel('Frequency (Hz)')
ylabel('|P1(f)|')
%% 播放去噪后的音频
% 播放去噪后的音频
disp('Playing low-pass filtered voice signal...');
sound(filtered_voice_lp, Fs_voice);
pause(length(filtered_voice_lp)/Fs_voice + 1);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
语音信号处理.zip (4个子文件)
KL123Z语音信号处理,200,14号
code2.m 1019B
code1.m 6KB
voiceWithHighFrequencyNoise.wav 648KB
highFrequencyNoise.wav 278KB
共 4 条
- 1
资源评论
时中´
- 粉丝: 9
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功