source: trunk/src/get_field/FFT.m @ 201

Last change on this file since 201 was 170, checked in by sommeria, 14 years ago

cleaning of documentation

File size: 3.0 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
11function GUI_input=FFT(hget_field)
12global spec x_vec
13%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
14if ~exist('hget_field','var')
15    GUI_input={'check_1Dplot'};
16    return %exit the function
17end
18GUI_input=[];
19%initiation
20hhget_field=guidata(hget_field);
21abscissa_list=get(hhget_field.abscissa,'String');
22val=get(hhget_field.abscissa,'Value');
23val=val(1);
24abscissa_name=abscissa_list{val};
25ordinate_list=get(hhget_field.ordinate,'String');
26val=get(hhget_field.ordinate,'Value');
27val=val(1); %take only the first variable in the list
28
29ordinate_name=ordinate_list{val};
30
31[Field,errormsg]=read_get_field(hget_field);
32if ~isempty(errormsg)
33    msgbox_uvmat('ERROR',['error in get_field/FFT input:' errormsg])
34    return
35end
36
37% get variable
38eval(['Var= Field.' ordinate_name ';']);
39np=size(Var);
40np_freq=floor(np(1)/2);
41dx=1;%default
42dfreq=1/np(1);%default frequency interval (abscissa= array index)
43sum_data=sum(Var,2);
44if ~isequal(abscissa_name,'')
45    eval(['Coord_x= Field.' abscissa_name ';']);
46    ind_select=find(~isinf(Coord_x)&~isnan(sum_data));%detect infinite values
47    Coord_x=Coord_x(ind_select);
48    Var=Var(ind_select,:);
49    diff_x=diff(Coord_x);
50    dx=min(diff_x);
51    %interpolate on a regular abscissa interval if needed
52    if (max(diff_x)-dx)> 0.001*dx || numel(ind_select)<np(1)
53        xequ=Coord_x(1):dx:Coord_x(end);%equal time spacingdx=
54        Var=interp1(Coord_x,Var,xequ); %interpolated func
55        np=size(Var);
56    end
57 %   funcinterp=interp1(time,func,timeq); %interpolated func
58    dfreq=1/(Coord_x(end)-Coord_x(1));%frequency interval
59end
60freq_max=1/(2*dx);
61Var=Var-ones(np(1),1)*mean(Var,1); %substract mean value
62fourier=fft(Var);%take fft (complex)
63spec=abs(fourier).*abs(fourier);% take square of the modulus
64spec=spec(1:np_freq,:);%keep only the first half (the other is symmetric)
65
66%plot
67list_fig=get(hhget_field.list_fig,'String');
68val=get(hhget_field.list_fig,'Value');
69hfig=str2num(list_fig{val});% chosen figure number from tyhe GUI
70if isempty(hfig)
71    hfig=figure;
72else
73    figure(hfig);
74end
75haxes=findobj(hfig,'Type','axes');
76if ~isempty(haxes)
77    axes(haxes)
78end
79x_vec=linspace(dfreq,freq_max,np_freq);
80plot(x_vec',spec)
81xlabel('frequency (Hz)')
82ylabel('spectral intensity')
83grid on
84
85%
86%
87% np=length(funcinterp);
88% funcinterp=funcinterp-sum(funcinterp)/np; %substract mean
89% fourier=fft(funcinterp);%take fft (complex)
90% spec=abs(fourier).*abs(fourier);% take sqare of the modulus
91% spec=spec([1:floor(np/2)]);%keep only the first half (the other is symmetric)
92% eval(['Field.' varname '=spec;'])
93% Field
94% % dfreq=1/(time(end)-time(1));%frequency interval
95% % freq=[0:dfreq:(floor(np/2)-1)*dfreq];
96% % figure(1)
97% % hold on
98% % plot(freq,spec)
99% % xlabel('frequency (Hz)')
100% % ylabel('spectral intensity')
101% % title(['spectrum of' fields]);
102% % grid on
103
Note: See TracBrowser for help on using the repository browser.