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

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

many bug corrections and cleaning. Activation of the BW option in uvmat. Improvement of the interaction of get_field with uvmat.

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