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

Last change on this file since 677 was 677, checked in by sommeria, 11 years ago

signal FFT introduced as transform_field for uvmat (reading of 1D fields)

File size: 2.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 DataOut=signal_FFT(DataIn)
12% global spec x_vec
13% %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
14% if ~exist('hget_field','var')
15%     GUI_input={'check_1Dplot'};
16%     return %exit the function
17% end
18% GUI_input=[];
19% %initiation
20% hhget_field=guidata(hget_field);
21% abscissa_list=get(hhget_field.abscissa,'String');
22% val=get(hhget_field.abscissa,'Value');
23% val=val(1);
24% abscissa_name=abscissa_list{val};
25% ordinate_list=get(hhget_field.ordinate,'String');
26% val=get(hhget_field.ordinate,'Value');
27% val=val(1); %take only the first variable in the list
28DataOut=DataIn;
29ordinate_name=DataIn.ListVarName{2};
30abscissa_name=DataIn.ListVarName{1};
31
32% get variable
33Var= DataIn.(ordinate_name);
34Coord_x= DataIn.(abscissa_name);
35np=size(Var);
36np_freq=floor(np(1)/2);
37dx=1;%default
38dfreq=1/np(1);%default frequency interval (abscissa= array index)
39sum_data=sum(Var,2);
40
41ind_select=find(~isinf(Coord_x)&~isnan(sum_data));%detect infinite values
42Coord_x=Coord_x(ind_select);
43Var=Var(ind_select,:);
44diff_x=diff(Coord_x);
45dx=min(diff_x);
46%interpolate on a regular abscissa interval if needed
47if (max(diff_x)-dx)> 0.001*dx || numel(ind_select)<np(1)
48    xequ=Coord_x(1):dx:Coord_x(end);%equal time spacingdx=
49    Var=interp1(Coord_x,Var,xequ); %interpolated func
50    np=size(Var);
51end
52%   funcinterp=interp1(time,func,timeq); %interpolated func
53dfreq=1/(Coord_x(end)-Coord_x(1));%frequency interval
54freq_max=1/(2*dx);
55Var=Var-ones(np(1),1)*mean(Var,1); %substract mean value
56fourier=fft(Var);%take fft (complex)
57spec=abs(fourier).*abs(fourier);% take square of the modulus
58spec=spec(1:np_freq,:);%keep only the first half (the other is symmetric)
59
60%plot
61figure(2);
62x_vec=linspace(dfreq,freq_max,np_freq);
63plot(x_vec',spec)
64xlabel('frequency (Hz)')
65ylabel('spectral intensity')
66grid on
67
Note: See TracBrowser for help on using the repository browser.