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

📄 dsp.m

📁 该程序是实现关于信号的一些重用的分析处理功能
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = DSP(varargin)% DSP Application M-file for DSP.fig%    FIG = DSP launch DSP GUI.%    DSP('callback_name', ...) invoke the named callback.% Last Modified by GUIDE v2.0 12-Jun-2007 16:05:44global m_InOne;if nargin == 0  % LAUNCH GUI	fig = openfig(mfilename,'reuse');	% Use system color scheme for figure:	set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));	% Generate a structure of handles to pass to callbacks, and store it. 	handles = guihandles(fig);	guidata(fig, handles);	if nargout > 0		varargout{1} = fig;	endelseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK	try		if (nargout)			[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard		else			feval(varargin{:}); % FEVAL switchyard		end	catch		disp(lasterr);	endend%| ABOUT CALLBACKS:%| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism.%|%| Each callback subfunction declaration has the following form:%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)%|%| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback',%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.%|%| H is the callback object's handle (obtained using GCBO).%|%| EVENTDATA is empty, but reserved for future use.%|%| HANDLES is a structure containing handles of components in GUI using%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This%| structure is created at GUI startup using GUIHANDLES and stored in%| the figure's application data using GUIDATA. A copy of the structure%| is passed to each callback.  You can store additional information in%| this structure at GUI startup, and you can change the structure%| during callbacks.  Call guidata(h, handles) after changing your%| copy to replace the stored original so that subsequent callbacks see%| the updates. Type "help guihandles" and "help guidata" for more%| information.%|%| VARARGIN contains any extra arguments you have passed to the%| callback. Specify the extra arguments by editing the callback%| property in the inspector. By default, GUIDE sets the property to:%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))%| Add any extra arguments after the last argument, before the final%| closing parenthesis.% --------------------------------------------------------------------function varargout = File_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = Open_Callback(h, eventdata, handles, varargin)[filename,pathname]=uigetfile({'*.txt','TXT-Files(*.txt)';...                               '*.*','All Files(*.*)'},...                               'Select A File');if isequal([filename,pathname],[0,0])   returnelse   File=fullfile(pathname,filename);endpath(path,pathname);[handles.Time,handles.Amp]=textread(File);plot(handles.Time,handles.Amp,'b');xlabel('Time(s)');ylabel('Velocity');Title('Time Domain Signal');handles.f = h;handles.x1 = 1;[t1,t2] = size(handles.Time);handles.x2 = t1;handles.len = t1;handles.m_Sec = 1;guidata(h, handles); % --------------------------------------------------------------------function varargout = Save_Callback(h, eventdata, handles, varargin)[filename,filepath]=uiputfile('*.txt','TXT file');dlmwrite(filename,handles.A,'\t');% --------------------------------------------------------------------function varargout = Exit_Callback(h, eventdata, handles, varargin)close all% --------------------------------------------------------------------function varargout = Process_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = Time_Callback(h, eventdata, handles, varargin)handles.x1 = 1;handles.x2 = handles.len;subplot(1,1,1);plot(handles.Time,handles.Amp,'b');xlabel('Time(s)');ylabel('Velocity');Title('Time Domain Signal');guidata(h,handles);% --------------------------------------------------------------------function varargout = FFT_Callback(h, eventdata, handles, varargin)subplot(2,1,1);plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'b');xlim([handles.Time(handles.x1) handles.Time(handles.x2)]);title('Original Time Signal');xlabel('Time(s)');ylabel('Velocity');F = fftshift(abs(fft(handles.Amp(handles.x1:handles.x2),256000)));freq = 1/handles.Time(2);len = handles.x2 - handles.x1;len = 256000;m = len/2;f = freq*(2:m)/len;%for real input, amplitude is symmetry, so just need display half %of the spectrumsubplot(2,1,2);%plot(f,log10(F(m+2:len)),'b');plot(f,F(m+2:len),'b');xlabel('Frequency/HZ');ylabel('Amplitude');title('Spectrum');B = F(m+2:len)';handles.A=[f,B];guidata(h, handles);% --------------------------------------------------------------------function varargout = Power_Callback(h, eventdata, handles, varargin)S=handles.Amp';M=zeros(1,handles.len);N=zeros(1,512);num = round(handles.len/512);for n=1:handles.len    M(n)=S(n).^2;endfor m=1:512    for n=(1+num*(m-1)):1:num*m        N(m)=N(m)+M(n);    endendsubplot(2,1,1);plot(handles.Time,handles.Amp,'b');title('Original Time Signal');xlabel('Time(s)');ylabel('Velocity');subplot(2,1,2);t = handles.Time(2)*num:handles.Time(2)*num:handles.Time(2)*num*512;plot(t,N);xlabel('Time(s)');ylabel('Amplitude');title('Power');% --------------------------------------------------------------------function varargout = AmplifyM_Callback(h, eventdata, handles, varargin)rect = getrect;x1 = round(rect(1)/handles.Time(2));x2 = round((rect(1)+rect(3))/handles.Time(2));if x2 < x1    xt = x2;    x2 = x1;    x1 = xt;end[handles.x1,handles.x2] = RangeSet(x1,x2,handles.len);plot(handles.Time(x1:x2),handles.Amp(x1:x2));xlim([handles.Time(x1) handles.Time(x2)]);xlabel('Time(s)');ylabel('Velocity');title('Part of Original Signal');guidata(h, handles);% --------------------------------------------------------------------function varargout = AmplifyI_Callback(h, eventdata, handles, varargin)x1 = str2num(get(handles.edit1,'String'));x2 = str2num(get(handles.edit2,'String'));x1 = round(x1/handles.Time(2));x2 = round(x2/handles.Time(2));[handles.x1,handles.x2] = RangeSet(x1,x2,handles.len);plot(handles.Time(x1:x2),handles.Amp(x1:x2));xlim([handles.Time(x1) handles.Time(x2)]);xlabel('Time(s)');ylabel('Velocity');title('Part of Original Signal');guidata(h, handles);% --------------------------------------------------------------------function varargout = MultiFile_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = Help_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function [x1, x2] = RangeSet(x1,x2,l)if x1 < 1    x1 = 1;endif x2 > l;    x2 = l;end% --------------------------------------------------------------------function varargout = Untitled_1_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = CompareTime_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = CompareFFT_Callback(h, eventdata, handles, varargin)subplot(2,2,1);plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'r');subplot(2,2,2);plot(handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'b');F1 = fftshift(abs(fft(handles.Amp(handles.x1:handles.x2))));F2 = fftshift(abs(fft(handles.Amp1(handles.x1:handles.x2))));freq = 1/handles.Time(2);len = handles.x2 - handles.x1;m = len/2;f = freq*(2:m)/len;%for real input, amplitude is symmetry, so just need display half %of the spectrumsubplot(2,2,3);plot(f,F1(m+2:len),'b');subplot(2,2,4);plot(f,F2(m+2:len),'b');% --------------------------------------------------------------------function varargout = Wavelet_Callback(h, eventdata, handles, varargin)c = cwt(handles.Amp(handles.x1:handles.x2),1:128,'db3');imagesc(c);title('Demo of Wavelet transform');xlabel('Time(s)');ylabel('Frequency(Hz)');% --------------------------------------------------------------------function varargout = edit1_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit2_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function PlotOneOrTwo(sec)if sec == 1    plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'b');else    plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'b',handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'r');end% --------------------------------------------------------------------function varargout = DisplayInOne_Callback(h, eventdata, handles, varargin)global m_InOne;m_InOne = 1;subplot(1,1,1);plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'b',handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'r');% --------------------------------------------------------------------function varargout = DisplayInTwo_Callback(h, eventdata, handles, varargin)global m_InOne;m_InOne = 2;subplot(2,1,1);plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'r');if handles.m_Sec == 2    subplot(2,1,2);    plot(handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'b');end% --------------------------------------------------------------------function varargout = Untitled_3_Callback(h, eventdata, handles, varargin)global m_InOne;rect = getrect;x1 = round(rect(1)/handles.Time(2));x2 = round((rect(1)+rect(3))/handles.Time(2));if x2 < x1    xt = x2;    x2 = x1;    x1 = xt;end[handles.x1,handles.x2] = RangeSet(x1,x2,handles.len);if m_InOne == 1;    subplot(1,1,1);    plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'b',handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'r');xlim([handles.Time(handles.x1) handles.Time(handles.x2)]);else    subplot(2,1,1);    plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'r');xlim([handles.Time(handles.x1) handles.Time(handles.x2)]);    subplot(2,1,2);    plot(handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'b');xlim([handles.Time(handles.x1) handles.Time(handles.x2)]);end    guidata(h, handles);% --------------------------------------------------------------------function varargout = OpenAnotherFile_Callback(h, eventdata, handles, varargin)global m_InOne;m_InOne = 2;[filename1,pathname1]=uigetfile({'*.txt','TXT-Files(*.txt)';...'*.*','All Files(*.*)'},...'Select Another File');if isequal([filename1,pathname1],[0,0])returnelseFile1=fullfile(pathname1,filename1);end[handles.Time1,handles.Amp1]=textread(filename1);subplot(2,1,1);plot(handles.Time(handles.x1:handles.x2),handles.Amp(handles.x1:handles.x2),'r');subplot(2,1,2);plot(handles.Time1(handles.x1:handles.x2),handles.Amp1(handles.x1:handles.x2),'b');handles.m_Sec = 2;guidata(h, handles);% --------------------------------------------------------------------function varargout = PowerTwo_Callback(h, eventdata, handles, varargin)%calculate first oneS=handles.Amp';M=zeros(1,handles.len);N1=zeros(1,512);N2=zeros(1,512);num = round(handles.len/512);for n=1:handles.len    M(n)=S(n).^2;endfor m=1:512    for n=(1+num*(m-1)):1:num*m        N1(m)=N1(m)+M(n);    endend%calculate the second oneS=handles.Amp1';M=zeros(1,handles.len);for n=1:handles.len    M(n)=S(n).^2;endfor m=1:512    for n=(1+num*(m-1)):1:num*m        N2(m)=N2(m)+M(n);    endendsubplot(2,1,1);plot(handles.Time,handles.Amp,'b',handles.Time,handles.Amp1,'r');title('Original Time Signal');xlabel('Time(s)');ylabel('Velocity');subplot(2,1,2);t = handles.Time(2)*num:handles.Time(2)*num:handles.Time(2)*num*512;plot(t,N1,'b',t,N2,'r');xlabel('Time(s)');ylabel('Amplitude');title('Power');% --------------------------------------------------------------------function varargout = JTFT_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = STFT_Callback(h, eventdata, handles, varargin)

⌨️ 快捷键说明

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