% 语音信号时域波形、短时幅值和短时过零率%%%%%%%%%%%%%%%%
%%语音信号变量y_sound; 短时幅值m1_y;短时能量m2_y;过零率zero_y%%%%
clear;
clc;
close all;
% [y_sound,Fs]=audioread( 'C:\Users\lenovo\Desktop\大三春季学期课程与项目\语音信号处理-黄青华\实验\实验一\my_voice\t.wav');%打开声音信号
[FileName,PathName]=uigetfile('*.wav'); % uigetfile动态选择文件
dir=[PathName,FileName]; % 实质就是文件的名字
[y_sound,Fs]=audioread(dir); % 读取特定路径下的语音文件
y_sound=y_sound(:,1); % 选择语音的单通道进行画图,如果不是那么画的是双通道的
y_length=length(y_sound); % 语音信号数字化之后的长度
T=0:(1/Fs):(y_length-1)/Fs; % 声音信号的时长
Ny=10*Fs/1000; %短时帧长,10ms
if Ny/2>fix(Ny/2) % 将Ny变成偶数
Ny=Ny-1;
else
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if y_length>Ny
frame_all=floor((y_length-(Ny/2))/(Ny/2)); %frame_moving equal to a half of frame_length, get number of all frame,,to use "enframe" too.
y2_sound=y_sound(1:(frame_all+1)*(Ny/2));
y3=reshape(y2_sound,(Ny/2),[]);
y4=[y3(:,1:frame_all);y3(:,2:(frame_all+1))];
else
frame_all=1;
y4=y_sound;
end
%%%%%%%加方窗
for i=1:(frame_all)
m1_y(i)=sum(abs(y4(:,i))); %计算短时幅值
m2_y(i)=sum(y4(:,i).*y4(:,i)); %计算短时能量
zero_y(i)=sum(abs(sign(y4(2:Ny,i))-sign(y4(1:(Ny-1),i))))/2; %计算短时过零率
end
%%%%%%%加哈明窗
win_h=hamming(Ny); %win_y=y_sound.*win_h;
for i=1:(frame_all)
mh1_y(i)=sum(abs(y4(:,i).*win_h)); %计算短时幅值
mh2_y(i)=sum((y4(:,i).*win_h).*(y4(:,i).*win_h)); %计算短时能量
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1);
% plot(T,y_sound,'b','LineWidth',2);grid on;
plot(T,y_sound,'b','LineWidth',1);grid on;
xlabel('时间/s');
title('d语音信号时域波形');
figure(2);
plot(m1_y,'--gs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',6)
hold on;
plot(zero_y,'-.r*','LineWidth',2,...
'MarkerFaceColor','r',...
'MarkerSize',8);
grid on;
xlabel('帧数');
title('短时幅值和短时过零率');
legend('幅值','过零率');
%
% figure(3);
% plot(m2_y,'--bo','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','g',...
% 'MarkerSize',6);hold on;
% plot(zero_y,'-ys','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','r',...
% 'MarkerSize',6);grid on;
% xlabel('帧数');
% title('短时能量和短时过零率');
% legend('能量','过零率');
%
% figure(4);
% plot(m1_y,':go','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','y',...
% 'MarkerSize',6);hold on;
% plot(m2_y,'-.ms','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','m',...
% 'MarkerSize',6);grid on;
% xlabel('帧数');
% title('短时幅值和短时能量');
% legend('幅值','能量');
%
% figure(5);
% plot(mh1_y,'--c>','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','g',...
% 'MarkerSize',6);hold on;
% plot(mh2_y,'-.ro','LineWidth',2,...
% 'MarkerEdgeColor','k',...
% 'MarkerFaceColor','m',...
% 'MarkerSize',6);grid on;
% xlabel('帧数');
% title('短时能量和短时幅值--hamming window');
% legend('幅值','能量');
%%%%%%%%计算短时过零率、短时幅值和短时能量的均值
% zero_mean=mean(zero_y);
% m1_mean=mean(m1_y);
% m2_mean=mean(m2_y);
return
%%
% 我的第一次试验的实验代码,主要就是测试d/ai/t/s
clear;
clc;
close all;
% [y_sound,Fs]=audioread('C:\Users\lenovo\Desktop\d.wav');%打开声音信号
[FileName,PathName]=uigetfile('*.wav'); %interactive read speech data
dir=[PathName,FileName]; %speech path
[y_sound,Fs]=audioread(dir);
y_sound=y_sound(:,1);
y_length=length(y_sound);
T=0:(1/Fs):(y_length-1)/Fs;
subplot(411);
plot(T,y_sound,'b');
grid on;
xlabel('时间/s');
title('/ong/时域波形');
[FileName,PathName]=uigetfile('*.wav'); %interactive read speech data
dir=[PathName,FileName]; %speech path
[y_sound,Fs]=audioread(dir);
y_sound=y_sound(:,1);
y_length=length(y_sound);
T=0:(1/Fs):(y_length-1)/Fs;
subplot(412);
plot(T,y_sound,'b');
grid on;
xlabel('时间/s');
title('/ing/时域波形');
[FileName,PathName]=uigetfile('*.wav'); %interactive read speech data
dir=[PathName,FileName]; %speech path
[y_sound,Fs]=audioread(dir);
y_sound=y_sound(:,1);
y_length=length(y_sound);
T=0:(1/Fs):(y_length-1)/Fs;
subplot(413);
plot(T,y_sound,'b');
grid on;
xlabel('时间/s');
title('/ang/时域波形');
[FileName,PathName]=uigetfile('*.wav'); %interactive read speech data
dir=[PathName,FileName]; %speech path
[y_sound,Fs]=audioread(dir);
y_sound=y_sound(:,1);
y_length=length(y_sound);
T=0:(1/Fs):(y_length-1)/Fs;
subplot(414);
plot(T,y_sound,'b');
grid on;
xlabel('时间/s');
title('/eng/时域波形');
%%
% 关于matlab读取语音信号的一个测试
[FileName,PathName]=uigetfile('*.wav'); %interactive read speech data
dir=[PathName,FileName]; %speech path
[y_sound,Fs]=audioread(dir);
y_sound=y_sound(:,1);
y_length=length(y_sound);
T=0:(1/Fs):(y_length-1)/Fs;
% subplot(222);
plot(T,y_sound,'b');
grid on;
xlabel('时间/s');
title('r时域波形');