matlab处理语音信号
matlab有处理语音信号的函数wavread,不过已经过时了,现在处理语音信号的函数名称是audioread选取4.wav进行处理(只有4的通道数为1)
利用hamming窗设计滤波器
Ham.m
function [N,h,H,w] = Ham (fp,fs,fc)wp = 2********* pi********* fp****/**** fc;ws = 2********* pi********* fs****/**** fc;wc = (ws****+**** wp)/ 2;dw = ws****-**** wp;N = 8********* pi****/**** dw;N = round(N);%向上取整 h = fir1(N****-**** 1,wc****/**** pi,'low',hann(N));H = fft(h,512);w = 2********* (0:511)/ 512;end
调用函数
clear;clc;[x,Fs] = audioread('4.wav');x = x(1:4096,:);X = fft(x);X = X****'**** ;
% 设置数字低通滤波器,选汉宁窗 fp = 1000;fs =1200;fc = 44100;%抽样频率 [N,h,H,w] = Ham(fp,fs,fc);
y = filter(h,1,x);Y = ifft(y);
figure(1)subplot(221)stem(x)title('原信号')subplot(222)stem(y)title('滤波后的信号')subplot(223)stem(abs(X))title('原信号频谱')subplot(224)stem(abs(Y))title('滤波后的信号频谱')
figure(2);stem(0:N****-**** 1,h);xlabel('n');ylabel('h(n)');axis([0 N****-**** 1 - 0.02 0.06]);title('汉宁窗的设计');grid on;
figure(3);subplot(2,1,1);plot(w,20********* log10(abs(H)));xlabel('\omega/\pi');ylabel('幅度dB');title('幅度特性');subplot(2,1,2);freqz(h)xlabel('\omega/\pi');ylabel('相位(度)');title('相位特性');
% 播放音频% sound(x,Fs)% sound(y,Fs)
%倒放音频 xd=flipud(x);yd=flipud(y);sound(xd,Fs)sound(yd,Fs)
Hamming窗如下
滤波器的频率响应如下
可以看出原波形与处理后的波形(看起来有点怪怪的)
补充:
倒放音频时参考
将数组从上向下翻转 - MATLAB flipud - MathWorks 中国ww2.mathworks.cn/help/matlab/ref/flipud.html
另外发现在命令行中输入filterDesigner并回车会弹出一个窗口
这样就可以用鼠标点点点,轻松设计滤波器了
5/2补充:
利用filterDesigner
选择第一个滤波器设计函数
保存为Filter_FIR.m
function Hd = Filter_FIR**%FILTER_FIR 返回离散时间滤波器对象。**
% MATLAB Code% Generated by MATLAB(R) 9.9 and DSP System Toolbox 9.11.% Generated on: 02-May-2023 22:45:33
% Equiripple FIR Lowpass filter designed using the FIRPM function.
% All frequency values are in Hz. Fs = 48000; % Sampling Frequency
Fpass = 9600; % Passband Frequency Fstop = 12000; % Stopband Frequency Dpass = 0.057501127785; % Passband Ripple Dstop = 0.0001; % Stopband Attenuation dens = 16; % Density Factor
% Calculate the order from the parameters using FIRPMORD. [N, Fo, Ao, W] = firpmord([Fpass, Fstop]/ (Fs****/**** 2), [1 0], [Dpass, Dstop]);
% Calculate the coefficients using the FIRPM function. b = firpm(N, Fo, Ao, W, {dens});Hd = dfilt.dffir(b);
% [EOF]
main.m
clear;clc;[x,Fs] = audioread('4.wav');x = x(1:4096,:);X = fft(x);X = X****'**** ;
y = filter(Filter_IIR,x);Y = ifft(y);
subplot(221)stem(x)title('原信号')subplot(222)stem(y)title('滤波后的信号')subplot(223)stem(abs(X))title('原信号频谱')subplot(224)stem(abs(Y))title('滤波后的信号频谱')