| 1 | function GUI_input=FFT(hget_field) |
|---|
| 2 | global spec x_vec |
|---|
| 3 | %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) |
|---|
| 4 | if ~exist('hget_field','var') |
|---|
| 5 | GUI_input={'check_1Dplot'}; |
|---|
| 6 | return %exit the function |
|---|
| 7 | end |
|---|
| 8 | |
|---|
| 9 | %initiation |
|---|
| 10 | hhget_field=guidata(hget_field); |
|---|
| 11 | % testinterp=0; |
|---|
| 12 | abscissa_list=get(hhget_field.abscissa,'String'); |
|---|
| 13 | val=get(hhget_field.abscissa,'Value'); |
|---|
| 14 | val=val(1); |
|---|
| 15 | abscissa_name=abscissa_list{val}; |
|---|
| 16 | ordinate_list=get(hhget_field.ordinate,'String'); |
|---|
| 17 | val=get(hhget_field.ordinate,'Value'); |
|---|
| 18 | val=val(1); %take only the first variable in the list |
|---|
| 19 | |
|---|
| 20 | %ordinate_name=Field.ListVarName{val}; |
|---|
| 21 | ordinate_name=ordinate_list{val}; |
|---|
| 22 | |
|---|
| 23 | [Field,errormsg]=read_get_field(hget_field); |
|---|
| 24 | if ~isempty(errormsg) |
|---|
| 25 | msgbox_uvmat('ERROR',['error in get_field/FFT input:' errormsg]) |
|---|
| 26 | return |
|---|
| 27 | end |
|---|
| 28 | |
|---|
| 29 | % get variable |
|---|
| 30 | eval(['Var= Field.' ordinate_name ';']); |
|---|
| 31 | np=size(Var); |
|---|
| 32 | np_freq=floor(np(1)/2); |
|---|
| 33 | dx=1;%default |
|---|
| 34 | dfreq=1/np(1);%default frequency interval (abscissa= array index) |
|---|
| 35 | if ~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 |
|---|
| 50 | end |
|---|
| 51 | freq_max=1/(2*dx); |
|---|
| 52 | Var=Var-ones(np(1),1)*mean(Var,1); %substract mean value |
|---|
| 53 | fourier=fft(Var);%take fft (complex) |
|---|
| 54 | spec=abs(fourier).*abs(fourier);% take square of the modulus |
|---|
| 55 | spec=spec(1:np_freq,:);%keep only the first half (the other is symmetric) |
|---|
| 56 | |
|---|
| 57 | %plot |
|---|
| 58 | list_fig=get(hhget_field.list_fig,'String'); |
|---|
| 59 | val=get(hhget_field.list_fig,'Value'); |
|---|
| 60 | hfig=str2num(list_fig{val})% chosen figure number from tyhe GUI |
|---|
| 61 | if isempty(hfig) |
|---|
| 62 | hfig=figure; |
|---|
| 63 | else |
|---|
| 64 | figure(hfig); |
|---|
| 65 | end |
|---|
| 66 | haxes=findobj(hfig,'Type','axes'); |
|---|
| 67 | if ~isempty(haxes) |
|---|
| 68 | axes(haxes) |
|---|
| 69 | end |
|---|
| 70 | x_vec=linspace(dfreq,freq_max,np_freq); |
|---|
| 71 | plot(x_vec',spec) |
|---|
| 72 | xlabel('frequency (Hz)') |
|---|
| 73 | ylabel('spectral intensity') |
|---|
| 74 | grid 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 | % |
|---|