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窗如下滤波器的频率响应如下