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