📄 firexpofn.m
字号:
function firexpofn(action,datastruct) if nargin < 1 action='init'; end % Fix freq labels % Apply filter shouldn't know about Undo 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); handles.exponum = 0; 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 set(handles.freqzoom,'Value',1.0); 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); linkedzoom([handles.timeplot, handles.specplot],'onx'); place_header(f,handles); case 'readinput' handles.audiodata = datastruct; clear datastruct; if (size(handles.audiodata.data,2) > 1) handles.audiodata.data = to_mono(handles.audiodata.data); end set(handles.freqzoom,'Value',1.0); 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); linkedzoom([handles.timeplot, handles.specplot],'onx'); place_header(f,handles); 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')); firexpofn 'freqzoom'; end 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')); firexpofn 'freqzoom'; end case 'normalize' if isfield(handles,'audiodata') handles.audiodata.data = normalize(handles.audiodata.data); xlim = get(handles.timeplot,'XLim'); 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.timeplot,'XLim',xlim); set(handles.specplot,'XLim',xlim); firexpofn 'freqzoom'; end case 'explore_data' explore_data(handles); case 'plotfreqz' plotfreqz(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); firexpofn '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 'save' if isfield(handles, 'audiodata') 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); firexpofn 'freqzoom'; end case {'pzexpo','pzfilterexpo'} [a_k,b_k] = designfilter(handles); [data.zeropos,data.polepos] = tf2zpk(b_k,a_k); switch action case 'pzexpo' pzexpogui(data); case 'pzfilterexpo' pzfilterexpogui(data); end case 'convexpo' [a_k,b_k] = designfilter(handles); data.impulse = b_k; convexpogui(data); case {'fourier'} if isfield(handles,'audiodata') audiodata = handles.audiodata; fourierexpogui(audiodata); 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); handles.t = [0:1/handles.audiodata.Fs:(length(handles.audiodata.data)-1)/... handles.audiodata.Fs]; axes(handles.timeplot) plot(handles.t,handles.audiodata.data) maxtime = length(handles.t)/handles.audiodata.Fs; set(handles.timeplot,'XLim',[0 maxtime]); set(handles.timeplot,'YLim',[-1.0 1.0]); grid; xlabel('time (s)');function handles = makeSpecPlot(handles); axes(handles.specplot); handles.pos = get(gca,'Position'); % Save axes position if (get(handles.interpolate,'Value')) if (get(handles.dBcheckbox,'Value')) pcolor(handles.st,handles.bin,20*log10(abs(handles.spectrum))); else pcolor(handles.st,handles.bin,abs(handles.spectrum)); end shading interp; else if (get(handles.dBcheckbox,'Value')) imagesc(handles.t,handles.bin,20*log10(abs(handles.spectrum))); else imagesc(handles.t,handles.bin,abs(handles.spectrum)); end end axis xy; ylabel('Frequency (Hz)'); colormap('Jet'); set(handles.specplot,'XTickLabel',['']); h = colorbar('vert'); if (get(handles.dBcheckbox,'Value')) set(get(h, 'YLabel'), 'String', 'dB'); else set(get(h, 'YLabel'), 'String', 'Amplitude');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -