function varargout = pinpufenxi(varargin)
% PINPUFENXI MATLAB code for pinpufenxi.fig
% PINPUFENXI, by itself, creates a new PINPUFENXI or raises the existing
% singleton*.
%
% H = PINPUFENXI returns the handle to a new PINPUFENXI or the handle to
% the existing singleton*.
%
% PINPUFENXI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PINPUFENXI.M with the given input arguments.
%
% PINPUFENXI('Property','Value',...) creates a new PINPUFENXI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pinpufenxi_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pinpufenxi_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help pinpufenxi
% Last Modified by GUIDE v2.5 05-Jan-2018 13:21:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pinpufenxi_OpeningFcn, ...
'gui_OutputFcn', @pinpufenxi_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
% End initialization code - DO NOT EDIT
% --- Executes just before pinpufenxi is made visible.
function pinpufenxi_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to pinpufenxi (see VARARGIN)
% Choose default command line output for pinpufenxi
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pinpufenxi wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pinpufenxi_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function from_Callback(hObject, eventdata, handles)
% hObject handle to from (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of from as text
% str2double(get(hObject,'String')) returns contents of from as a double
% --- Executes during object creation, after setting all properties.
function from_CreateFcn(hObject, eventdata, handles)
% hObject handle to from (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function to_Callback(hObject, eventdata, handles)
% hObject handle to to (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of to as text
% str2double(get(hObject,'String')) returns contents of to as a double
% --- Executes during object creation, after setting all properties.
function to_CreateFcn(hObject, eventdata, handles)
% hObject handle to to (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
if get(hObject,'Value')==0.0
set(handles.from,'Enable','on');
set(handles.to,'Enable','on');
else
set(handles.from,'String','1','Enable','off');
set(handles.to,'String',get(handles.samplenum,'String'),'Enable','off');
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Fs = str2double(get(findobj('Tag','samplerate'),'String'));
from = str2double(get(findobj('Tag','from'),'String'));
to = str2double(get(findobj('Tag','to'),'String'));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%过零检测
n=1;
ymax=max([handles.y(1) handles.y(2)]);
ymin=min([handles.y(1) handles.y(2)]);
if from<1 | to-from<5;
msgbox('Error range!');
return;
end
for i=from+2:to-1;
if handles.y(i-1)<0 & handles.y(i-2)<0 & handles.y(i)>=0 & handles.y(i+1)>0
if handles.y(i)==0
ti(n)=i;
else
ti(n)=i-handles.y(i)/(handles.y(i)-handles.y(i-1));
end
amp(n)=(ymax-ymin)/2;
ymax=0;
ymin=0;
n=n+1;
else
if ymax<handles.y(i)
ymax=handles.y(i);
end
if ymin>handles.y(i)
ymin=handles.y(i);
end
end
end
n=n-1;
%freqence and periodicity
for i=1:n-1
T(i)=ti(i+1)-ti(i);
end
freq = Fs/mean(T);
set(handles.outt,'String',1/freq);
set(handles.outfreq,'String',num2str(freq));
set(handles.outamp,'String',num2str(mean(amp(2:n-1))));
phase = 2*pi*(1-(ti(1:n-1)-1)./T +floor((ti(1:n-1)-1)./T));
set(handles.outphase,'String',num2str(mean(phase)));
set(handles.outpeak,'String',(max(handles.y(from:to))-min(handles.y(from:to)))/2);
set(handles.outmean,'String',mean(handles.y(from:to)));
set(handles.outmeansquare,'String',mean(handles.y(from:to).^2));
set(handles.outs,'String',std(handles.y(from:to))^2);
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
from=str2double(get(handles.from,'string'));
to=str2double(get(handles.to,'string'));
Fs = str2double(get(findobj('Tag','samplerate'),'String'));
sample=handles.y(from:to); %首先提取待分析的样本,将其存入sample中
f=linspace(0,Fs/2,(to-from+1)/2); %生成离散化的频率点,以采样频率作为离散化的间隔
Y=fft(sample,to-from+1); %对样本作快速傅里叶变换,变换结果存入Y中
[C,I]=max(abs(Y)); %获得幅值最大的点及其对应的下标值1,则f(I)为最大的幅值所对应的频率,即信号频率的估计值
set(handles.foutt,'string',1/f(I)); %计算并输出周期的估计值
set(handles.foutfreq,'string',f(I)); %输出频率的估计值
Y=Y(1:(to-from+1)/2); %为与f对应,只取Y的前半部分
plot(handles.plot1,f,2*sqrt(Y.*conj(Y))); %绘制幅值曲线
plot(handles.plot2,f,angle(Y));
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
音频分析仪.rar (3个子文件)
数字信号处理实验七
pinpufenxi.m 33KB
pinpufenxi.fig 30KB
tts.wav 1.44MB
共 3 条
- 1
资源评论
黄上城
- 粉丝: 155
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功