语音信号的滤波处理matlab源码

%%%%%%%%%%% Read the sound file %%%%%%%%%%%
close all;
clear all;
[Y,Fs,NBITS] = wavread('dsp01_noise.wav');

%%%%%%%%%%% Play the sound %%%%%%%%%%%
sound(Y,Fs);
pause(4);

%%%%%%%%%%% Plot the noisy speech signal in time-domain
subplot(321);plot(Y(1:30000));
title('Time-domain plot of the input')
xlabel('Sample number')

%%%%%%%%%%% Plot the noisy speech signal in frequency-domain
XF = fft(Y,Fs);
f = 0:1:Fs-1;
subplot(322);plot(f(1:Fs/2),abs(XF(1:Fs/2)))
axis([0 3000 0 max(abs(XF))]);
title('Frequency components of the input')
xlabel('Frequency "Hz"')

%%%%%%%%%%% BP filter designed by fdatool
load BP_num;
Ybp = filter(Num,1,Y);
% sound(Ybp,Fs);
% pause(4);

%%%%%%%%%%% 1-D Median filter design
NM = 25;
Ynm = medfilt1(Ybp,NM);
sound(2*Ynm,Fs);
pause(4);

%%%%%%%%%%% Save the filtered sound file
wavwrite(Ynm,Fs,'FilteredSig.wav');

%%%%%%%%%%% Plot the filtered speech signal in time-domain
subplot(323);plot(Ynm(1:30000));
title('Time-domain plot of the filtered signal')
xlabel('Sample number')

%%%%%%%%%%% Plot the filtered speech signal in frequency-domain
XF = fft(Ynm,Fs);
f = 0:1:Fs-1;
subplot(324);plot(f(1:Fs/2),abs(XF(1:Fs/2)))
axis([0 3000 0 max(abs(XF))]);
title('Frequency components of the filtered signal')
xlabel('Frequency "Hz"')

%%%%%%%%%%% Load the filtered sound file
[x,Fs]=wavread('FilteredSig.wav');

%%%%%%%%%%% 4 stage Comb filter design
c1=0.6;
c2=0.4;
c3=0.2;
c4=0.1;

%   Delay coefficients for the combfilter stage
R1=1000;
R2=1500;
R3=900;
R4=800;

%   Combfilter 1
num1=[0,zeros(1,R1-1),1];
den1=[1,zeros(1,R1-1),-c1];
combfilt1=filter(num1,den1,x);

%   Combfilter 2
num2=[0,zeros(1,R2-1),1];
den2=[1,zeros(1,R2-1),-c2];
combfilt2=filter(num2,den2,x);

%   Combfilter 3
num3=[0,zeros(1,R3-1),1];
den3=[1,zeros(1,R3-1),-c3];
combfilt3=filter(num3,den3,x);

%   Combfilter 4
num4=[0,zeros(1,R4-1),1];
den4=[1,zeros(1,R4-1),-c4];
combfilt4=filter(num4,den4,x);

combfilt=combfilt1+combfilt2+combfilt3+combfilt4;

%%%%%%%%%%% 2 stage All Pass filter design
%   Determine the order of the All Pass Filters
R5=900;
R6=900;

AN1=0.7;    %   All Pass Numerator constant Stage 1
AN2=0.6;    %   All Pass Numerator constant Stage 2

level = 0.7;


AD1=450;    %   All Pass Denuminator constant Stage 1
AD2=390;    %   All Pass Denuminator constant Stage 2

%   All Pass stage 1
APnum=[AN1,zeros(1,R5-1),1]; %All Pass Numerator
APden=[1,zeros(1,R5-1),AN1]; %All Pass Denumator

AllPass1 = filter(APnum,APden,combfilt);
num=[AN2,zeros(1,R6-1),1];
den=[1,zeros(1,R6-1),AN2];

%   All Pass stage 2
AllPass2 = filter(num,den,AllPass1);

%   Add the echoes into the original signal and scale down level of echo
REVERB = x + level * 3*AllPass2; 
soundsc(REVERB,Fs);

%%%%%%%%%%% Plot the reverb signal in time-domain
subplot(325);plot(REVERB(1:30000));
xlabel('Time Variant'); ylabel('signal level');
title('Filtered Signal + REVERB');

%%%%%%%%%%% Plot the noisy speech signal in frequency-domain
XF = fft(REVERB,Fs);
f = 0:1:Fs-1;
subplot(326);plot(f(1:Fs/2),abs(XF(1:Fs/2)))
axis([0 3000 0 max(abs(XF))]);
title('Frequency components of the reverb')
xlabel('Frequency "Hz"')
 

你可能感兴趣的:(MATLAB,板块3:通信与信号处理)