zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Matlab:语音信号处理与滤波

MATLAB 语音 信号处理 滤波
2023-06-13 09:11:26 时间

大家好,又见面了,我是你们的朋友全栈君。

文章目录
  • 语音信号的采集
  • 对语音信号进行频谱分析
  • 设计数字滤波器
  • 利用滤波器进行滤波

注:本文章仅供参考,本人并非通信专业,相关知识早已忘得差不多了,所以不要再问我相关问题啦~sorry

语音信号的采集

首先利用win自带的录音机(没有的话手机录也行),录下一段语音信号,时间40秒左右。运用MATLAB对语音进行采样

[x,fs]=audioread('D:\1234.mp3');
plot(x);

出现如下的图


对语音信号进行频谱分析

处理语音信号的时域波形图 对语音信号进行快速傅立叶变换,得到信号的频谱

clear
[x,fs]=audioread('D:\1234.mp3');
x=x(:,1);
FS=length(x);
X=fft(x);
t=(0:FS-1)/fs;
figure(1)

subplot(2,1,1);plot(t,x);
title('原始语音信号时域波形');
xlabel('时间');
ylabel('赋值');
grid on;

subplot(2,1,2);plot(abs(X));
title('原始语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 8]);
grid on;

设计数字滤波器

可以运用窗函数法、双线性变换法设计低通、高通、带通三种滤波器。本次选用双线性变换法进行设计

(1) 利用ellipord函数设计IIR低通滤波器

Fp=1500;
Fs=1200;
Ft=8000;
As=100;
Ap=1;
wp=2*pi*Fp/Ft;
ws=2*pi*Fs/Ft;
[n,wn]=ellipord(wp,ws,Ap,As,'s');
[b,a]=ellip(n,Ap,As,wn,'s');
[B,A]=bilinear(b,a,1);
[h,w]=freqz(B,A);
figure(2);
plot(w*Ft/pi/2,abs(h));
title('IIR低通滤波器');
xlabel('频率');
ylabel('幅度');
grid on;

(2) 利用ellipord函数设计IIR高通滤波器

Fp=1200;
Fs=2200;
Ft=8000;
As=100;
Ap=1;
wp=2*pi*Fp/Ft;
ws=2*pi*Fs/Ft;
[n,wn]=ellipord(wp,ws,Ap,As,'s');
[b,a]=ellip(n,Ap,As,wn,'high','s');
[B,A]=bilinear(b,a,1);
[h,w]=freqz(B,A);
figure(4);
plot(w*Ft/pi/2,abs(h));
title('IIR高通滤波器');
xlabel('频率');
ylabel('幅度');
grid on;

(3) 利用ellipord函数设计IIR带通滤波器

Fp1=1200;
Fp2=3000;
Fs1=1000;
Fs2=3200;
Ft=8000;
As=100;
Ap=1;
wp=[2*pi*Fp1/Ft,2*pi*Fp2/Ft];
ws=[2*pi*Fs1/Ft,2*pi*Fs2/Ft];
[n,wn]=ellipord(wp,ws,Ap,As,'s');
[b,a]=ellip(n,Ap,As,wn,'s');
[B,A]=bilinear(b,a,1);
[h,w]=freqz(B,A);
figure(6);
plot(w*Ft/pi/2,abs(h));
title('IIR带通滤波器');
xlabel('频率');
ylabel('幅度');
grid on;

利用滤波器进行滤波

(1)IIR低通滤波器

[x,fs]=audioread('D:\1234.mp3');
x=x(:,1);
Y=fft(x);
y=filter(B,A,x);
Y1=fft(y);
n=0:length(x)-1;
t=(0:FS-1)/fs;
figure(7);
subplot(3,1,1);plot(t,y);grid on;
title('IIR低通滤波器滤波后语音信号时域波形');
xlabel('时间');
ylabel('赋值');
subplot(3,1,2);plot(n,abs(Y));grid on;
title('滤波前语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 8]);
subplot(3,1,3);plot(n,abs(Y1));grid on;
title('滤波后语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 8]);

(2)IIR高通滤波器

[x,fs]=audioread('D:\1234.mp3');
x=x(:,1);
Y=fft(x);
y=filter(B,A,x);
Y1=fft(y);
n=0:length(x)-1;
t=(0:FS-1)/fs;
figure(7);
subplot(3,1,1);plot(t,y);grid on;
title('IIR高通滤波器滤波后语音信号时域波形');
xlabel('时间');
ylabel('赋值');
subplot(3,1,2);plot(n,abs(Y));grid on;
title('滤波前语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 8]);
subplot(3,1,3);plot(n,abs(Y1));grid on;
title('滤波后语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 8]);

(3) IIR带通滤波器

[x,fs]=audioread('D:\1234.mp3');
x=x(:,1);
Y=fft(x);
y=filter(B,A,x);
Y1=fft(y);
n=0:length(x)-1;
t=(0:FS-1)/fs;
figure(7);
subplot(3,1,1);plot(t,y);grid on;
title('IIR带通滤波器滤波后语音信号时域波形');
xlabel('时间');
ylabel('赋值');
subplot(3,1,2);plot(n,abs(Y));grid on;
title('滤波前语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 5]);
subplot(3,1,3);plot(n,abs(Y1));grid on;
title('滤波后语音信号频谱');
xlabel('频率');
ylabel('幅度');
axis([0 1000000 0 5]);

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/141091.html原文链接:https://javaforall.cn