source: trunk/src/transform_field/signal_FFT.m @ 920

Last change on this file since 920 was 908, checked in by g7moreau, 9 years ago
  • Update Copyright to 2015
File size: 2.9 KB
Line 
1% 'FFT': calculate and display spectrum of the field selected in the GUI  get_field
2%  GUI_input=FFT(hget_field)
3%
4% OUTPUT:
5% GUI_input: option for display in the GUI get_field
6%
7%INPUT:
8% hget_field: handles of the GUI get_field
9
10%=======================================================================
11% Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
12%   http://www.legi.grenoble-inp.fr
13%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
14%
15%     This file is part of the toolbox UVMAT.
16%
17%     UVMAT is free software; you can redistribute it and/or modify
18%     it under the terms of the GNU General Public License as published
19%     by the Free Software Foundation; either version 2 of the license,
20%     or (at your option) any later version.
21%
22%     UVMAT is distributed in the hope that it will be useful,
23%     but WITHOUT ANY WARRANTY; without even the implied warranty of
24%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25%     GNU General Public License (see LICENSE.txt) for more details.
26%=======================================================================
27
28function DataOut=signal_FFT(DataIn)
29% global spec x_vec
30% %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
31% if ~exist('hget_field','var')
32%     GUI_input={'check_1Dplot'};
33%     return %exit the function
34% end
35% GUI_input=[];
36% %initiation
37% hhget_field=guidata(hget_field);
38% abscissa_list=get(hhget_field.abscissa,'String');
39% val=get(hhget_field.abscissa,'Value');
40% val=val(1);
41% abscissa_name=abscissa_list{val};
42% ordinate_list=get(hhget_field.ordinate,'String');
43% val=get(hhget_field.ordinate,'Value');
44% val=val(1); %take only the first variable in the list
45DataOut=DataIn;
46ordinate_name=DataIn.ListVarName{2};
47abscissa_name=DataIn.ListVarName{1};
48
49% get variable
50Var= DataIn.(ordinate_name);
51Coord_x= DataIn.(abscissa_name);
52np=size(Var);
53np_freq=floor(np(1)/2);
54dx=1;%default
55dfreq=1/np(1);%default frequency interval (abscissa= array index)
56sum_data=sum(Var,2);
57
58ind_select=find(~isinf(Coord_x)&~isnan(sum_data));%detect infinite values
59Coord_x=Coord_x(ind_select);
60Var=Var(ind_select,:);
61diff_x=diff(Coord_x);
62dx=min(diff_x);
63%interpolate on a regular abscissa interval if needed
64if (max(diff_x)-dx)> 0.001*dx || numel(ind_select)<np(1)
65    xequ=Coord_x(1):dx:Coord_x(end);%equal time spacingdx=
66    Var=interp1(Coord_x,Var,xequ); %interpolated func
67    np=size(Var);
68end
69%   funcinterp=interp1(time,func,timeq); %interpolated func
70dfreq=1/(Coord_x(end)-Coord_x(1));%frequency interval
71freq_max=1/(2*dx);
72Var=Var-ones(np(1),1)*mean(Var,1); %substract mean value
73fourier=fft(Var);%take fft (complex)
74spec=abs(fourier).*abs(fourier);% take square of the modulus
75spec=spec(1:np_freq,:);%keep only the first half (the other is symmetric)
76
77%plot
78figure(2);
79x_vec=linspace(dfreq,freq_max,np_freq);
80plot(x_vec',spec)
81xlabel('frequency (Hz)')
82ylabel('spectral intensity')
83grid on
84
Note: See TracBrowser for help on using the repository browser.