[677] | 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 |
---|
[810] | 9 | |
---|
| 10 | %======================================================================= |
---|
[1107] | 11 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[810] | 12 | % http://www.legi.grenoble-inp.fr |
---|
| 13 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
[677] | 14 | % |
---|
[810] | 15 | % This file is part of the toolbox UVMAT. |
---|
| 16 | % |
---|
| 17 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 18 | % it under the terms of the GNU General Public License as published |
---|
| 19 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 20 | % or (at your option) any later version. |
---|
| 21 | % |
---|
| 22 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 25 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 26 | %======================================================================= |
---|
[677] | 27 | |
---|
| 28 | function DataOut=signal_FFT(DataIn) |
---|
| 29 | % global spec x_vec |
---|
| 30 | % %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) |
---|
| 31 | % if ~exist('hget_field','var') |
---|
| 32 | % GUI_input={'check_1Dplot'}; |
---|
| 33 | % return %exit the function |
---|
| 34 | % end |
---|
| 35 | % GUI_input=[]; |
---|
| 36 | % %initiation |
---|
| 37 | % hhget_field=guidata(hget_field); |
---|
| 38 | % abscissa_list=get(hhget_field.abscissa,'String'); |
---|
| 39 | % val=get(hhget_field.abscissa,'Value'); |
---|
| 40 | % val=val(1); |
---|
| 41 | % abscissa_name=abscissa_list{val}; |
---|
| 42 | % ordinate_list=get(hhget_field.ordinate,'String'); |
---|
| 43 | % val=get(hhget_field.ordinate,'Value'); |
---|
| 44 | % val=val(1); %take only the first variable in the list |
---|
| 45 | DataOut=DataIn; |
---|
| 46 | ordinate_name=DataIn.ListVarName{2}; |
---|
| 47 | abscissa_name=DataIn.ListVarName{1}; |
---|
| 48 | |
---|
| 49 | % get variable |
---|
| 50 | Var= DataIn.(ordinate_name); |
---|
| 51 | Coord_x= DataIn.(abscissa_name); |
---|
| 52 | np=size(Var); |
---|
| 53 | np_freq=floor(np(1)/2); |
---|
| 54 | dx=1;%default |
---|
| 55 | dfreq=1/np(1);%default frequency interval (abscissa= array index) |
---|
| 56 | sum_data=sum(Var,2); |
---|
| 57 | |
---|
| 58 | ind_select=find(~isinf(Coord_x)&~isnan(sum_data));%detect infinite values |
---|
| 59 | Coord_x=Coord_x(ind_select); |
---|
| 60 | Var=Var(ind_select,:); |
---|
| 61 | diff_x=diff(Coord_x); |
---|
| 62 | dx=min(diff_x); |
---|
| 63 | %interpolate on a regular abscissa interval if needed |
---|
| 64 | if (max(diff_x)-dx)> 0.001*dx || numel(ind_select)<np(1) |
---|
| 65 | xequ=Coord_x(1):dx:Coord_x(end);%equal time spacingdx= |
---|
| 66 | Var=interp1(Coord_x,Var,xequ); %interpolated func |
---|
| 67 | np=size(Var); |
---|
| 68 | end |
---|
| 69 | % funcinterp=interp1(time,func,timeq); %interpolated func |
---|
| 70 | dfreq=1/(Coord_x(end)-Coord_x(1));%frequency interval |
---|
| 71 | freq_max=1/(2*dx); |
---|
| 72 | Var=Var-ones(np(1),1)*mean(Var,1); %substract mean value |
---|
| 73 | fourier=fft(Var);%take fft (complex) |
---|
| 74 | spec=abs(fourier).*abs(fourier);% take square of the modulus |
---|
| 75 | spec=spec(1:np_freq,:);%keep only the first half (the other is symmetric) |
---|
| 76 | |
---|
| 77 | %plot |
---|
| 78 | figure(2); |
---|
| 79 | x_vec=linspace(dfreq,freq_max,np_freq); |
---|
| 80 | plot(x_vec',spec) |
---|
| 81 | xlabel('frequency (Hz)') |
---|
| 82 | ylabel('spectral intensity') |
---|
| 83 | grid on |
---|
| 84 | |
---|