function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function untitled_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled_OutputFcn(~, ~, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(~, ~, handles)
global bit SingleC Number_of_Wave_Data_Point SingleCn;
[file,path]=uigetfile('*.m4a;*.mp3;*.wav;*.flac');
set(handles.text3,'String',[path,file]); % 将路径及文件名显示在文本框中
[y,Fs] = audioread([path,file]);
bit=Fs;
SingleC=y(:,1); % 抽取第 1 声道 即抽取其中一维数组
SingleCn=SingleC;
Single_Channel_Max = max(abs(SingleC)); %幅值数据归一化
Single_Channel_Wave = SingleC/Single_Channel_Max; %幅值重构
Number_of_Wave_Data_Point = length(Single_Channel_Wave);
Time_Single_Channel_Wave=(0:Number_of_Wave_Data_Point-1)/bit; %计算数据点时刻 , 需要将横轴的纯数字点转化为时间(秒)
axes(handles.axes1);
plot(Time_Single_Channel_Wave,Single_Channel_Wave); %调取数据点,绘制图像
xlabel('时间/s','FontSize',10,'FontWeight','bold');
ylabel('幅值','FontSize',10,'FontWeight','bold');
axes(handles.axes2);
Single_Channel_Wave_Fft = fft(SingleC);
Fft_Xabel=(0 : Number_of_Wave_Data_Point/2)*bit / Number_of_Wave_Data_Point; %提取一般数据,以绘制单边谱波形
Single_Channel_Wave_Fft_Max = max(abs(Single_Channel_Wave_Fft)); %幅值数据归一化
Single_Channel_Wave_Fft = Single_Channel_Wave_Fft/Single_Channel_Wave_Fft_Max; %幅值重构
plot(Fft_Xabel,abs(Single_Channel_Wave_Fft (1 : Number_of_Wave_Data_Point / 2 +1)));%调用数据,绘制图像,以Fft_Xabel的数据为横轴数据,
xlabel('频率/Hz','FontSize',10,'FontWeight','bold');
ylabel('频率幅值','FontSize',10,'FontWeight','bold');
function nc_Callback(~, ~, handles)
global bit SingleC Number_of_Wave_Data_Point SingleCn;
noise=wgn(Number_of_Wave_Data_Point,1,1);
SingleCn=SingleC+0.05*noise; %加入高斯白噪声
Single_Channel_Max = max(abs(SingleCn)); %幅值数据归一化
Single_Channel_Wave = SingleCn/Single_Channel_Max; %幅值重构
Time_Single_Channel_Wave=(0:Number_of_Wave_Data_Point-1)/bit; %计算数据点时刻 , 需要将横轴的纯数字点转化为时间(秒)
axes(handles.axes1);
plot(Time_Single_Channel_Wave,Single_Channel_Wave); %调取数据点,绘制图像
xlabel('时间/s','FontSize',10,'FontWeight','bold');
ylabel('幅值','FontSize',10,'FontWeight','bold');
axes(handles.axes2);
Single_Channel_Wave_Fft = fft(SingleCn);
Fft_Xabel=(0 : Number_of_Wave_Data_Point/2)*bit / Number_of_Wave_Data_Point; %提取一般数据,以绘制单边谱波形
Single_Channel_Wave_Fft_Max = max(abs(Single_Channel_Wave_Fft)); %幅值数据归一化
Single_Channel_Wave_Fft = Single_Channel_Wave_Fft/Single_Channel_Wave_Fft_Max; %幅值重构
plot(Fft_Xabel,abs(Single_Channel_Wave_Fft (1 : Number_of_Wave_Data_Point / 2 +1)));%调用数据,绘制图像,以Fft_Xabel的数据为横轴数据,
xlabel('频率/Hz','FontSize',10,'FontWeight','bold');
ylabel('频率幅值','FontSize',10,'FontWeight','bold');
set(handles.uipanel2,'Title','加噪后的时域波形和频谱图');
Time_Noise=(0:Number_of_Wave_Data_Point-1)/bit; %计算数据点时刻
Noise_Max = max(abs(SingleCn)); %幅值数据归一化
SingleCn = SingleCn/Noise_Max; %幅值重构
axes(handles.axes3);
plot(Time_Noise,0.05*noise,'r');
xlabel('时间/s');
ylabel('幅值');
function stp_Callback(~, ~, ~)
clear sound;
function pushbutton11_Callback(~, ~, handles)
global bit SingleC Number_of_Wave_Data_Point SingleCn;
SingleCn=SingleC;
Single_Channel_Max = max(abs(SingleCn)); %幅值数据归一化
Single_Channel_Wave = SingleCn/Single_Channel_Max; %幅值重构
Time_Single_Channel_Wave=(0:Number_of_Wave_Data_Point-1)/bit; %计算数据点时刻 , 需要将横轴的纯数字点转化为时间(秒)
axes(handles.axes1);
plot(Time_Single_Channel_Wave,Single_Channel_Wave); %调取数据点,绘制图像
xlabel('时间/s','FontSize',10,'FontWeight','bold');
ylabel('幅值','FontSize',10,'FontWeight','bold');
axes(handles.axes2);
Single_Channel_Wave_Fft = fft(SingleCn);
Fft_Xabel=(0 : Number_of_Wave_Data_Point/2)*bit / Number_of_Wave_Data_Point; %提取一般数据,以绘制单边谱波形
Single_Channel_Wave_Fft_Max = max(abs(Single_Channel_Wave_Fft)); %幅值数据归一化
Single_Channel_Wave_Fft = Single_Channel_Wave_Fft/Single_Channel_Wave_Fft_Max; %幅值重构
plot(Fft_Xabel,abs(Single_Channel_Wave_Fft (1 : Number_of_Wave_Data_Point / 2 +1)));%调用数据,绘制图像,以Fft_Xabel的数据为横轴数据,
xlabel('频率/Hz','FontSize',10,'FontWeight','bold');
ylabel('频率幅值','FontSize',10,'FontWeight','bold');
set(handles.uipanel2,'Title','原始信号的时域波形和频谱图');
axes(handles.axes3);
plot(0);
xlabel('时间/s');
ylabel('幅值');
function pc_Callback(~, ~, handles)
global SingleCn bit
sound(SingleCn,0.5*get(handles.spd,'value')*bit);