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

📄 pzfilterexpofn.m

📁 非常好的数字处理教程
💻 M
📖 第 1 页 / 共 2 页
字号:
% This code borrows heavily from MAD polezero demonstrationfunction pzfilterexpo(action,datastruct)    if nargin < 1        action='init';    end	% Colormap isn't working as predicted    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.timeplot);			reset(handles.pz_plot);			reset(handles.Hz_plot);			handles.Fs = 44100;			handles.npoints = 256;			makePZPlot(handles);			handles = makeHzPlot(handles);			set(gcf,'KeyPressFcn','pzfilterexpofn keypressed');		case 'loadsound'			handles.audiodata = load_audiodata;            handles.original = handles.audiodata;            if ~isfield(handles.audiodata, 'filenamepath')                return;            end            if (size(handles.audiodata.data,2) > 1)                handles.audiodata.data = to_mono(handles.audiodata.data);            end            handles.Fs = handles.audiodata.Fs;            contents = get(handles.fftsize,'String');            fftsize = str2double(contents{get(handles.fftsize,'Value')});            contents = get(handles.Window,'String');            shape = contents{get(handles.Window,'Value')};            [handles.spectrum, handles.bin, handles.st] = ...                spectrogram(handles.audiodata, fftsize, shape);            handles = makeTimePlot(handles);            handles = makeSpecPlot(handles);            handles = makeHzPlot(handles);            handles = updateHzPlot(handles);            linkedzoom([handles.timeplot, handles.specplot],'onx');            place_header(f,handles);            set(handles.freqzoom,'Value',1);		case 'readinput'			if isfield(datastruct,'polepos')				handles.Fs = 44100;				handles = makeHzPlot(handles);                if isfield(datastruct, 'gain')                    set(handles.gain,'String',num2str(datastruct.gain));                end				z = datastruct.zeropos; 				% Remove zeros from 0				z = z(find(z));				zc = conj(z);				elem = find(z == zc);				if (elem > 0) 					% Add just a bit so that the plot doesn't make them invisible					mult = 0.00000;					z = [z(1:elem-1); z(elem)+j*mult; z(elem)-j*mult; z(elem+1:end)];					datastruct.zeropos = z;				end 				p = datastruct.polepos;				% Remove poles from 0				p = p(find(p));				pc = conj(p);				elem = find(p == pc);				if (elem > 0)					mult = 0.00000;					p = [p(1:elem-1); p(elem)+j*mult; p(elem)-j*mult; p(elem+1:end)];					datastruct.polepos = p;				end				for i=1:length(datastruct.zeropos)/2,					x = real(datastruct.zeropos(i*2-1));					y = imag(datastruct.zeropos(i*2-1));					p1=text('Parent',handles.pz_plot,'Position',[x y],...						'String','o','ButtonDownFcn','pzfilterexpofn selectzero',...						'EraseMode','xor','Tag','Zero',...						'HorizontalAlignment','center');					if y ~= 0,						p2=text('Parent',handles.pz_plot,'Position',[x -y],...							'String','o','ButtonDownFcn','pzfilterexpofn selectzero',...							'EraseMode','xor','Tag','Zero',...							'HorizontalAlignment','center');						set(p1,'UserData',p2);						set(p2,'UserData',p1);					end				end				for i=1:length(datastruct.polepos)/2,					x = real(datastruct.polepos(i*2-1));					y = imag(datastruct.polepos(i*2-1));					p1=text('Parent',handles.pz_plot,'Position',[x y],...						'String','x','ButtonDownFcn','pzfilterexpofn selectpole',...						'EraseMode','xor','Tag','Pole',...						'HorizontalAlignment','center');					if y ~= 0,						p2=text('Parent',handles.pz_plot,'Position',[x -y],...							'String','x','ButtonDownFcn','pzfilterexpofn selectpole',...							'EraseMode','xor','Tag','Pole',...							'HorizontalAlignment','center');						set(p1,'UserData',p2);						set(p2,'UserData',p1);					end				end				handles = updateHzPlot(handles);			else				handles.audiodata = datastruct;				clear datastruct;				if (size(handles.audiodata.data,2) > 1)					handles.audiodata.data = to_mono(handles.audiodata.data);				end				handles.original = handles.audiodata;				contents = get(handles.fftsize,'String');				fftsize = str2double(contents{get(handles.fftsize,'Value')});				contents = get(handles.Window,'String');				shape = contents{get(handles.Window,'Value')};				[handles.spectrum, handles.bin, handles.st] = ...					spectrogram(handles.audiodata, fftsize, shape);				handles = makeTimePlot(handles);				handles = makeSpecPlot(handles);				handles = makeHzPlot(handles);				handles = updateHzPlot(handles);            	linkedzoom([handles.timeplot, handles.specplot],'onx');            	place_header(f,handles);            	set(handles.freqzoom,'Value',1);			end        case {'playsound', 'playoriginal'}            if isfield(handles, 'audiodata')                times = get(handles.specplot,'XLim');                switch action                    case 'playsound'                        audiodata = handles.audiodata;                        button = handles.play;                    case 'playoriginal'                        audiodata = handles.original;                        button = handles.playoriginal;                end                samples = floor(times*audiodata.Fs);                if (samples(1) <= 0)                   samples(1) = 1;                end                if (samples(2) > length(audiodata.data))                   samples(2) = length(audiodata.data);                end                audiodata.data = audiodata.data(samples(1):samples(2));                if (max(abs(audiodata.data)) > 1.0)                    audiodata.data = normalize(audiodata.data);                end                play_audiodata(audiodata, button);            end		case {'db','inverse','interpolate','colormap','fftdisplay'}			if isfield(handles, 'audiodata')                updateSpecPlot(handles);                set(handles.specplot,'XLim',get(handles.timeplot,'XLim'));                pzfilterexpofn 'freqzoom';            end		case 'Hz_logf'			if get(handles.Hz_logf,'Value')				set(handles.Hz_plot,'XScale','log');			else				set(handles.Hz_plot,'XScale','linear');			end        case 'Hz_dB'            axes(handles.Hz_plot);			if get(handles.dB,'Value')				set(handles.Hz_plot,'YLim',[-80 1]);    			ylabel('Normalized Attenuation (dB)');			else				%set(handles.freq_plot,'YLim',[0 1.05]);                %set(handles.freq_plot,'YLimMode','auto');    			ylabel('Normalized Attenuation');			end			pzfilterexpofn 'plotfreqz'		case {'fftsize','window'}			if isfield(handles, 'audiodata')                contents = get(handles.fftsize,'String');                fftsize = str2double(contents{get(handles.fftsize,'Value')});                contents = get(handles.Window,'String');                shape = contents{get(handles.Window,'Value')};                [handles.spectrum, handles.bin, handles.st] = ...                    spectrogram(handles.audiodata, fftsize, shape);                updateSpecPlot(handles);                set(handles.specplot,'XLim',get(handles.timeplot,'XLim'));                pzfilterexpofn 'freqzoom';            end		case 'normalize'            if isfield(handles, 'audiodata')				handles.audiodata.data = normalize(handles.audiodata.data);				handles = makeTimePlot(handles);                contents = get(handles.fftsize,'String');                fftsize = str2double(contents{get(handles.fftsize,'Value')});                contents = get(handles.Window,'String');                shape = contents{get(handles.Window,'Value')};                [handles.spectrum, handles.bin, handles.st] = ...                    spectrogram(handles.audiodata, fftsize, shape);                updateSpecPlot(handles);                set(handles.specplot,'XLim',get(handles.timeplot,'XLim'));                pzfilterexpofn 'freqzoom';			end		case 'freqzoom'             if isfield(handles,'audiodata')                val = get(handles.freqzoom,'Value');                if val == 0,                    val = 0.001;                 end                Fs = handles.audiodata.Fs;                set(handles.specplot,'YLim',[0 val*Fs/2])            end        case 'zoomreset'            if isfield(handles,'audiodata')                handles = makeTimePlot(handles);                set(handles.specplot,'XLim',get(handles.timeplot,'XLim'));                linkedzoom([handles.timeplot, handles.specplot],'onx');            end		case 'fourier'			if isfield(handles,'audiodata')				fourierexpogui(handles.audiodata);			end		case 'addzero'			handles = add_coef(handles,'zero');			pzfilterexpofn 'plotfreqz'		case 'addpole'			handles = add_coef(handles,'pole');			pzfilterexpofn 'plotfreqz'		case 'selectpole'			handles = select_coef(handles,'pole');		case 'selectzero'			handles = select_coef(handles,'zero');		case 'movepole'			handles = move_coef(handles);			pzfilterexpofn 'plotfreqz'		case 'movezero'			handles = move_coef(handles);			pzfilterexpofn 'plotfreqz'		case 'releaseobject'			set(gcf,'WindowButtonMotionFcn','');			set(gcf,'WindowButtonUpFcn','');			%set([handles.currentcoef handles.partnercoef],'Selected','off');			pzfilterexpofn 'plotfreqz'		case 'plotfreqz'			handles = updateHzPlot(handles);		case 'loadvowel'			axes(handles.pz_plot);			cla;			delete(findobj(gcf,'Selected','on'))			makePZPlot(handles);			bws=[0.03 0.07 0.1];    %formant freqs from Rabiner & Juang			switch datastruct				case 'beet'					freqs=[270 2290 3010];				case 'bit'					freqs=[390 1990 2550];				case 'bet'					freqs=[530 1840 2480];				case 'bat'					freqs=[660 1720 2410];				case 'bart'					freqs=[730 1090 2440];				case 'bort'					freqs=[570 840 2410];				case 'but'					freqs=[440 1020 2240];				case 'boot'					freqs=[300 870 2240];				case 'bert'					freqs=[490 1350 1690];				otherwise			end			% convert freqs and bws to PZ locations			angs=2*pi*freqs/handles.Fs;			for fr=1:length(freqs)				[x,y]=pol2cart(angs(fr),1-bws(fr));				p1=text('Parent',handles.pz_plot,'Position',[x y],...					'String','x','ButtonDownFcn','pzfilterexpofn selectpole',...					'EraseMode','xor','Tag','Pole','HorizontalAlignment','center');				p2=text('Parent',handles.pz_plot,'Position',[x -y],...					'String','x','ButtonDownFcn','pzfilterexpofn selectpole',...					'EraseMode','xor','Tag','Pole','HorizontalAlignment','center');				set(p1,'UserData',p2);				set(p2,'UserData',p1);			end            handles = updateHzPlot(handles);		case 'apply_filter'            if isfield(handles, 'audiodata')                handles = apply_filter(handles);                contents = get(handles.fftsize,'String');                fftsize = str2double(contents{get(handles.fftsize,'Value')});                contents = get(handles.Window,'String');                shape = contents{get(handles.Window,'Value')};                        [handles.spectrum, handles.bin, handles.st] = ...                    spectrogram(handles.audiodata, fftsize, shape);                updateSpecPlot(handles);                Xlim = get(handles.timeplot,'XLim');                handles = makeTimePlot(handles);                set(handles.specplot,'XLim',Xlim);                set(handles.timeplot,'XLim',Xlim);                pzfilterexpofn 'freqzoom';            end		case 'keypressed'			% if delete key is pressed, delete any selected object				if double(get(gcf,'CurrentCharacter')) == 8					delete(findobj(gcf,'Selected','on'))				end				pzfilterexpofn 'plotfreqz'        case 'save'            if isfield(handles.audiodata,'data')				save_audiodata(handles.audiodata);			end		case 'undo'            if isfield(handles,'audiodata')			    handles = undo(handles);			    updateSpecPlot(handles);                Xlim = get(handles.timeplot,'XLim');			    handles = makeTimePlot(handles);                set(handles.specplot,'XLim',Xlim);                set(handles.timeplot,'XLim',Xlim);                pzfilterexpofn 'freqzoom';            end		case 'convexpo'			polepos=findobj(handles.pz_plot,'Tag','Pole');            zeropos=findobj(handles.pz_plot,'Tag','Zero');            pp = [];            zz = [];             for p=1:length(polepos)                 ppos=get(polepos(p),'Position');                pp(p)=complex(ppos(1),ppos(2));            end             for z=1:length(zeropos)                 zp=get(zeropos(z),'Position');                zz(z)=complex(zp(1),zp(2));            end			[num,den]=zp2tf(zz',pp',1);			data.impulse = filter(num, den,[1 zeros(1,99)]);			convexpogui(data);		case 'pzexpo'			polepos=findobj(handles.pz_plot,'Tag','Pole');            zeropos=findobj(handles.pz_plot,'Tag','Zero');

⌨️ 快捷键说明

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