⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 endpointexpofn.m

📁 非常好的数字处理教程
💻 M
📖 第 1 页 / 共 2 页
字号:
function endpointexpofn(action,datastruct)    if nargin < 1        action='init';    end	name = mfilename;	figname = [name(1:end-2) '_fig'];	f=findobj('Tag',figname);    handles = get(f,'UserData');    switch action		case 'help'			display_help(figname);        case 'init'            setdefaults;			reset(handles.specplot);            reset(handles.rmsplot);			reset(handles.zcplot);			reset(handles.timeplot);            set(handles.rmsplot,'XTickLabel','');            set(handles.timeplot,'XTickLabel','');		case 'loadsound'			handles.audiodata = load_audiodata;			if ~isfield(handles.audiodata, 'filenamepath')					return;			end			if (size(handles.audiodata.data,2) > 1)				handles.audiodata.data = to_mono(handles.audiodata.data);			end			% Pre-emphasize			handles.audiodata.data = filter([1 -.9], 1, handles.audiodata.data);			if (handles.audiodata.Fs > 8000)					handles.audiodata.data = resample(handles.audiodata.data, ...							8000, handles.audiodata.Fs);					handles.audiodata.Fs = 8000;			end			handles.stats = getStatistics(handles);			handles = makeDataPlot(handles,'time');			handles = makeDataPlot(handles,'spectrum');            handles = makeDataPlot(handles,'rms');			handles = makeDataPlot(handles,'zc');            handles = findEndpoints(handles);			place_header(f, handles);		case 'readinput'			handles.audiodata = datastruct;            clear datastruct;			handles.audiodata.filenamepath = '';			handles.audiodata.nBits = 16;			handles.audiodata;            			handles.stats = getStatistics(handles);			handles = makeDataPlot(handles,'time');			handles = makeDataPlot(handles,'spectrum');            handles = makeDataPlot(handles,'rms');			handles = makeDataPlot(handles,'zc');            handles = findEndpoints(handles);			place_header(f, handles);		case 'playsound'			if isfield(handles, 'audiodata')				audiodata = handles.audiodata;				if (max(abs(audiodata.data)) > 1.0)					audiodata.data = normalize(audiodata.data);				end				play_audiodata(audiodata, handles.play);            end        case 'play_endpoint'            if isfield(handles, 'audiodata')				audiodata = handles.audiodata;                samples = floor(handles.endpoints*handles.audiodata.Fs+1);                audiodata.data = audiodata.data(samples(1):samples(2),1);				if (max(abs(audiodata.data)) > 1.0)					audiodata.data = normalize(audiodata.data);				end				play_audiodata(audiodata, handles.play);            end        case 'updateanalysis'            handles.stats = getStatistics(handles);            handles = makeDataPlot(handles,'time');            handles = makeDataPlot(handles,'rms');			handles = makeDataPlot(handles,'zc');            handles = findEndpoints(handles);        case 'updateendpt'            handles = makeDataPlot(handles,'time');            handles = makeDataPlot(handles,'rms');			handles = makeDataPlot(handles,'zc');            handles = findEndpoints(handles);        case 'updatelpc'            handles = makeDataPlot(handles,'spectrum');		case {'fftsize','window'}			if isfield(handles, 'audiodata')				contents = get(handles.fftsize,'String');				fftsize = contents{get(handles.fftsize,'Value')};				if strncmp(fftsize,'Entire',6)					fftsize = length(handles.audiodata.data);				else					fftsize = str2num(fftsize);				end				if (fftsize > length(handles.audiodata.data))					h = errordlg('FFTSize larger than data size!');					uiwait(h);					set(handles.fftsize,'Value',1);					fftsize = str2num(contents{get(handles.fftsize,'Value')});				end				wintime = fftsize/handles.audiodata.Fs;				handles.right = handles.left + wintime;                if handles.right > handles.maxtime                    handles.right = handles.maxtime;                    handles.left = handles.maxtime - wintime;                end                set(handles.l,'XData',[handles.left handles.left]);				set(handles.r,'XData',[handles.right handles.right]);				handles = makeDataPlot(handles,'time');				handles = makeDataPlot(handles,'spectrum');				handles = findEndpoints(handles);			end		case 'normalize'            if isfield(handles,'audiodata')                handles.audiodata.data = normalize(handles.audiodata.data);                handles = makeDataPlot(handles,'time');%                 handles = makeDataPlot(handles,'spectrum');%                 handles = makeDataPlot(handles,'rms');%                 handles = makeDataPlot(handles,'zc');                handles = findEndpoints(handles);            end		% The following taken in large part from MAD.		case 'left'			set(gcf,'WindowButtonMotionFcn','endpointexpofn moveleft');			set(gcf,'WindowButtonUpFcn','endpointexpofn release');		case 'right'			set(gcf,'WindowButtonMotionFcn','endpointexpofn moveright');			set(gcf,'WindowButtonUpFcn','endpointexpofn release');		case 'moveleft'			handles = moveleft(handles);			updateSpecPlot(handles);		case 'moveright'			handles = moveright(handles);			updateSpecPlot(handles);		case 'release'			set(gcf,'WindowButtonMotionFcn','');			set(gcf,'WindowButtonUpFcn','');            refresh(f);        case {'sonogram', 'alias'}            if isfield(handles,'audiodata'),                audiodata = handles.audiodata;			    switch action					case 'sonogram'				    	sonoexpogui(audiodata);					case 'alias'                    	aliasexpogui(audiodata);			    end            end		case 'print'			print_figure(f);		case 'close'			close_figure(f,figname(1:end-4));			return;	end	set(f,'UserData',handles);    % --------------------------------------------------------------------function handles = makeTimePlot(handles);	contents = get(handles.fftsize,'String');	fftsize = contents{get(handles.fftsize,'Value')};	if strncmp(fftsize,'Entire',6)		fftsize = length(handles.audiodata.data);	else		fftsize = str2num(fftsize);	end	axes(handles.timeplot);	cla;	handles.t = [0:1/handles.audiodata.Fs:(length(handles.audiodata.data)-1)/...			handles.audiodata.Fs];	maxtime = length(handles.t)/handles.audiodata.Fs;    handles.maxtime = maxtime;	handles.winleft = 0;	handles.winright = maxtime;	if max(handles.audiodata.data) > 1		handles.audiodata.data = normalize(handles.audiodata.data);	end	plot(handles.t,handles.audiodata.data)	set(handles.timeplot,'NextPlot','replacechildren','Drawmode','fast',...			'XLim',[0 maxtime], 'YLim', [-1.1 1.1],'YTickLabel','');	grid on;	hold on;    handles.left = 0.1*maxtime;    handles.delta = fftsize/handles.audiodata.Fs;    handles.right = handles.left + handles.delta;    handles.l=line([handles.left handles.left],get(gca,'YLim'),'Color','r',...		'ButtonDownFcn','endpointexpofn left','LineWidth', 2,'EraseMode','xor');    handles.r=line([handles.right handles.right],get(gca,'YLim'),'Color','r',...		'ButtonDownFcn','endpointexpofn right','LineWidth', 2,'EraseMode','xor');	handles.step=0.2*maxtime;    function ud = makeDataPlot(ud,type)    t = linspace(0,size(ud.audiodata.data,1)/ud.audiodata.Fs,...                size(ud.stats.zc,1));            	signal = ud.audiodata.data;    switch type        case 'time'            cla(ud.timeplot);            ud = makeTimePlot(ud);            set(ud.timeplot,'XTickLabel','');            grid on;        case 'spectrum'            cla(ud.specplot);            ud = makeSpecPlot(ud);            grid on;        case 'rms'            cla(ud.rmsplot);            axes(ud.rmsplot);            plot(t,ud.stats.logen);            set(ud.rmsplot,'XTickLabel','');            ylabel('Log RMS');            grid on;            axis([0 max(t) min(ud.stats.logen)*1.1 5]);        case 'zc'            cla(ud.zcplot);            axes(ud.zcplot);            plot(t,ud.stats.zc);            ylabel('Mean Zero Crossings');            xlabel('Time (s)');            grid on;            axis([0 max(t) 0 max(ud.stats.zc)*1.1]);    end    function handles = makeSpecPlot(handles);	contents = get(handles.fftsize,'String');	fftsize = contents{get(handles.fftsize,'Value')};	if strncmp(fftsize,'Entire',6)		fftsize = length(handles.audiodata.data);	else		fftsize = str2num(fftsize);	end	contents = get(handles.Window,'String');	shape = contents{get(handles.Window,'Value')};	axes(handles.specplot);	% Get x-position of samples	startpos = floor(handles.left*handles.audiodata.Fs+1);	signal = handles.audiodata.data(startpos:startpos+fftsize-1).*...			get_windowdata(fftsize, shape);    freqs = linspace(-handles.audiodata.Fs/2,handles.audiodata.Fs/2,fftsize);    % find and plot formant    p = str2num(get(handles.lpcorder,'String'));    R = xcorr(signal,'coeff');    R = R(fftsize:end);    R = R(1:p+1);    Rt = toeplitz(R(1:end-1));    alpha = inv(Rt)*R(2:end);    H = freqz(1,[1 -alpha'],fftsize/2);    Hmag = 20*log10(1e-10+abs(H));    maxXmag = max(Hmag);    Hmag = Hmag - maxXmag;    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -