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

📄 time_frec_distribution.m

📁 主成分分析和偏最小二乘SquaresPrincipal成分分析( PCA )和偏最小二乘( PLS )
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = time_frec_distribution(varargin)
% time_frec_distribution creates time-frecuency distribution of time series
% [tfd,t,f]=time_frec_distribution(x,giu_mode,method,param);
% Parameters:
% x - data vector or structure with fields
%    .data - data vector
%    .time - time vector
% gui_mode - 'gui' or 'silent' (no gui)
% method - 
%  1 - Born-Jordan distribution 
%  2 - Binomial distribution 
%  3 - quasi-Wigner distribution 
%  4 - Levin distribution
%  5 - Rihaczek distribution
%  6 - Page distribution 
%  7 - Margenau-Hill distribution 
%  8 - Spectrogram 
%  9 - Short-time Fourier Transform 
% For methods 1-3 param is a length of rectangular lag window on the autocorr. function (even)
% For methods 4-7 no parameters required
% For methods 8-9 param is a duration of gaussian window (odd)
%
% Based on DiscreteTFD
% Jeffrey O'Neill <jeffo@bu.edu>
% 8 St. Mary's Street
% Boston, MA 02135

% Last Modified by GUIDE v2.5 22-Oct-2004 17:03:50
% last modified 8.01.04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @time_frec_distribution_OpeningFcn, ...
                   'gui_OutputFcn',  @time_frec_distribution_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 time_frec_distribution is made visible.
function time_frec_distribution_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to time_frec_distribution (see VARARGIN)

% Choose default command line output for time_frec_distribution
global tfdDATA

handles.output = hObject;
guidata(hObject, handles);

set(hObject,'name','Time-frequency distribution ');
set([handles.t_fsw handles.e_l_fsw],'visible','off');
if isempty(varargin)
    error('Not enought input parameters');
end
if isa(varargin{1},'struct')
    tfdDATA.data=varargin{1};
else
    tfdDATA.data.data=varargin{1};
    tfdDATA.data.time=1:length(varargin{1});
end

if rem(length(tfdDATA.data.data),2)==0
	set(handles.e_l_tsw,'string',num2str(length(tfdDATA.data.data)));
else
	set(handles.e_l_tsw,'string',num2str(length(tfdDATA.data.data)-1));
end


if length(varargin)>1
    if strcmp(varargin{2},'gui')|strcmp(varargin{2},'silent')
        tfdDATA.gui_mode=varargin{2};
    else
        warning('Wrong value of ''gui_mode'' parameter. ''gui_mode'' set to ''gui''');
        tfdDATA.gui_mode='gui';
    end
else
    tfdDATA.gui_mode='gui';
end
tfdDATA.autocalc=0;

if length(varargin)>2
    set(handles.method,'value',varargin{3});
end
if length(varargin)>=3
	switch varargin{3} % method
    case {1,2,3}
        set([handles.t_fsw handles.e_l_fsw],'visible','off');
        set([handles.t_tsw handles.t_l_tsw handles.e_l_tsw ],'visible','on');
		if length(varargin)>3
            tfdDATA.autocalc=1;
            set(handles.e_l_tsw,'string',num2str(varargin{4}));
        end
    case {4,5,6,7} 
        set([handles.t_fsw handles.e_l_fsw],'visible','off');
        set([handles.t_tsw handles.t_l_tsw handles.e_l_tsw ],'visible','off');
		tfdDATA.autocalc=1;
    case {8,9} 
        set([handles.t_fsw handles.e_l_fsw],'visible','on');
        set([handles.t_tsw handles.t_l_tsw handles.e_l_tsw ],'visible','off');
		if length(varargin)>3
            tfdDATA.autocalc=1;
            set(handles.e_l_fsw,'string',num2str(varargin{4}));
        end
	end
end

% UIWAIT makes time_frec_distribution wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = time_frec_distribution_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
global tfdDATA tfdOUT

if tfdDATA.autocalc
    compute_Callback(handles.compute, [], handles);
    varargout{1} =tfdOUT.tfd;
    varargout{2} =tfdOUT.t;
    varargout{3} =tfdOUT.f;
    if strcmp(tfdDATA.gui_mode,'silent')
		try
            close(handles.figure);
		catch
		end
    end
else
    uiwait;
	try
        varargout{1} =tfdOUT.tfd;
        varargout{2} =tfdOUT.t;
        varargout{3} =tfdOUT.f;
	catch
	end
end

% --- Executes on button press in cancel.
function cancel_Callback(hObject, eventdata, handles)
% hObject    handle to cancel (see GCBO)
% handles    structure with handles and user data (see GUIDATA)
close(gcf);

% --- Executes on button press in compute.
function compute_Callback(hObject, eventdata, handles)
% hObject    handle to compute (see GCBO)
% handles    structure with handles and user data (see GUIDATA)
global tfdDATA tfdOUT

I=get(handles.method,'value');
w=str2num(get(handles.e_l_fsw,'string'));

wlen=str2num(get(handles.e_l_tsw,'string'));
Dt=diff(tfdDATA.data.time);
if max(Dt-mean(Dt))>1e-10
    warndlg('Time instants is not equally spaced. Frequency scale is wrong.','Warning');
end
fs=1/Dt(1);
nfreq=length(tfdDATA.data.data);

switch I
    case 1
		[tfd, t, f] = born_jordan2(tfdDATA.data.data, fs, nfreq, wlen);
    case 2
		[tfd, t, f] = binomial2(tfdDATA.data.data, fs, nfreq, wlen);
    case 3
		[tfd, t, f] = qwigner2(tfdDATA.data.data, fs, nfreq, wlen);
    case 4
		[tfd, t, f] = levin2(tfdDATA.data.data, fs, nfreq);
    case 5
		[tfd, t, f] = rihaczek2(tfdDATA.data.data, fs, nfreq);
    case 6
		[tfd, t, f] = page2(tfdDATA.data.data, fs, nfreq);
    case 7
		[tfd, t, f] = margenau_hill2(tfdDATA.data.data, fs, nfreq);
    case 8
        [tfd,t,f] = spec2(tfdDATA.data.data,fs,nfreq,1,w,'short');
    case 9
        [tfd,t,f] = stft2(tfdDATA.data.data,fs,nfreq,1,w,'short');
end
tfdOUT.tfd=tfd;
tfdOUT.t=t;
tfdOUT.f=f;
if strcmp(tfdDATA.gui_mode, 'gui')
	axes(handles.ax);
	colormap('jet');
	if get(handles.las,'Value')
        ptfd(tfd, t, f, 8);
	else
		ptfddb(tfd, 25,t, f, 8)
	end
end

% --- Executes during object creation, after setting all properties.
function e_l_fsw_CreateFcn(hObject, eventdata, handles)
% hObject    handle to e_l_fsw (see GCBO)
% 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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
set(hObject,'string',num2str(5));



function e_l_fsw_Callback(hObject, eventdata, handles)
% hObject    handle to e_l_fsw (see GCBO)
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of e_l_fsw as text
%        str2double(get(hObject,'String')) returns contents of e_l_fsw as a double


% --- Executes during object creation, after setting all properties.
function e_l_tsw_CreateFcn(hObject, eventdata, handles)
% hObject    handle to e_l_tsw (see GCBO)
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
% global tfdDATA

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function e_l_tsw_Callback(hObject, eventdata, handles)
% hObject    handle to e_l_tsw (see GCBO)
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of e_l_tsw as text
%        str2double(get(hObject,'String')) returns contents of e_l_tsw as a double


% --- Executes during object creation, after setting all properties.
function method_CreateFcn(hObject, eventdata, handles)
% hObject    handle to method (see GCBO)
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
str='Born-Jordan distribution'; % 1
str=[str '|Binomial distribution']; % 2
str=[str '|quasi-Wigner distribution']; % 3
str=[str '|Levin distribution']; % 4
str=[str '|Rihaczek distribution']; % 5
str=[str '|Page distribution']; % 6
str=[str '|Margenau-Hill distribution']; % 7
str=[str '|Spectrogram']; % 8
str=[str '|Short-time Fourier Transform']; % 9

set(hObject,'string',str);

% --- Executes on selection change in method.
function method_Callback(hObject, eventdata, handles)
% hObject    handle to method (see GCBO)
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns method contents as cell array
%        contents{get(hObject,'Value')} returns selected item from method
I=get(hObject,'value');
switch I
    case {1,2,3}
        set([handles.t_fsw handles.e_l_fsw],'visible','off');
        set([handles.t_tsw handles.t_l_tsw handles.e_l_tsw ],'visible','on');
    case {4,5,6,7} 
        set([handles.t_fsw handles.e_l_fsw],'visible','off');
        set([handles.t_tsw handles.t_l_tsw handles.e_l_tsw ],'visible','off');
    case {8,9} 
        set([handles.t_fsw handles.e_l_fsw],'visible','on');
        set([handles.t_tsw handles.t_l_tsw handles.e_l_tsw ],'visible','off');
end

% --- Executes on button press in das.
function das_Callback(hObject, eventdata, handles)
% hObject    handle to das (see GCBO)
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of das
set(hObject,'Value',1);
set(handles.las,'value',~get(hObject,'Value'));

% --- Executes on button press in las.
function las_Callback(hObject, eventdata, handles)
% hObject    handle to las (see GCBO)
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of las
set(hObject,'Value',1);
set(handles.das,'value',~get(hObject,'Value'));



%%% DiscreteTFD's functions (Type2,(3): discrete and aperiodic; continuous and periodic) %%% 

% Copyright (C) 1997, 1998, 1999  Jeffrey C. O'Neill
% Copyright (C) 1998, 1999  Boston University
% Copyright (C) 1997, 1998  L'Ecole Normale Superieure de Lyon
% Copyright (C) 1997  The Regents of the University of Michigan
% All Rights Reserved
% 
% Jeffrey O'Neill <jeffo@bu.edu>
% 8 St. Mary's Street
% Boston, MA 02135
% 
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
function [tfd, t, f] = binomial2(x, fs, nfreq, wlen)
% binomial2 -- Compute samples of the type II binomial distribution.
%
%  Usage
%    [tfd, t, f] = binomial2(x, fs, nfreq, wlen)
%
%  Inputs
%    x     signal vector
%    fs    sampling frequency of x (optional, default is 1 sample/second)
%    nfreq number of samples to compute in frequency (optional, default
%          is twice the length of x)
%    wlen  length of the rectangular lag window on the auto-correlation
%          function, must be less than or equal to nfreq (optional, default
%          is twice the length of x)
%
%  Outputs
%    tfd  matrix containing the binomial distribution of signal x.  If x has
%         length N, then tfd will be nfreq by N. (optional)
%    t    vector of sampling times (optional)
%    f    vector of frequency values (optional)

% Copyright (C) -- see DiscreteTFDs/Copyright

% specify defaults
x = x(:);
N = length(x);

error(nargchk(1, 4, nargin));
if (nargin < 4) 
  wlen = 2*N;
end
if (nargin < 3)
  nfreq = 2*N;
end
if (nargin < 2)
  fs = 1;

⌨️ 快捷键说明

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