clc
close all
clear all
fs = 8000;
[fname,pname] = uigetfile('input.wav','Open Wave File'); %选择输入音频文件
file = [pname,fname];
[x,fc,bits] = wavread(file); %对音频文件进行采样
%[x,fc,bits] = wavread('input0.wav');
%sound(x,fc);
X = fft(x,1024); %对音频的数据进行FFT变换
f = fs*(1:512)/1024;
figure(1); %画图
plot(x); %画原始语音信号时域图
title('原始语音信号');
xlabel('时间 t');
ylabel('幅值 n');
figure(2);
freqz(x); %画原始语音信号频率响应图
title('频率响应图')
figure(3) %画原始语音信号频域图
subplot(2,1,1)
plot(abs(X(1:512)))
title('原始语音信号FFT频谱')
xlabel('Hz')
subplot(2,1,2)
plot(f,abs(X(1:512)))
title('原始语音信号频谱')
xlabel('Hz')
figure(4)
n=25; %采用25阶低通滤波器
window=hamming(50); %汉明窗(Hamming Window)函数
b=fir1(n,0.25)*100; %截止频率为1000Hz,增益40db,得出b的数据
freqz(b,1,8000); %传递函数的幅频响应和相频响应
figure(5)
y = filter(b,1,x); %对音频信号进行滤波
Y = fft(y,1024); %对滤波后的音频信号进行FFT变换
plot(y) %画滤波后的音频信号的时域图
title('滤波后的时域语音信号')
xlabel('时间 t')
ylabel('幅值 n')
figure(6) %画滤波后的音频信号的频域图
subplot(2,1,1)
plot(abs(Y(1:512)))
title('滤波后的频域FFT频谱')
xlabel('Hz');
subplot(2,1,2)
plot(f,abs(Y(1:512)))
title('滤波后的频域语音信号频谱')
xlabel('Hz')
sound(y,fc); %播放滤波后的音频信号
wavwrite(y,fc,bits,'output'); %生成滤波后的音频文件
xout = x/max(x); %生成滤波后的dat文件,作为CCS仿真滤波器的输入信号
xto_ccs = abs(round(32767*xout));
myfile = fopen('indata.dat','w');
fprintf(myfile,'1651 1 2d8 1 12c \n');
fprintf(myfile,'\n %d \n',xto_ccs);
fclose(myfile);
评论2