%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [x_power_spec,y_power_spec,h, NFFT]= plot_powerspec(d,data,all,t_start,t_stop,plotOption, loglin) Plots a simple power spectrum of requested data Takes sample length by looking at difference between adjacent timestamps N.B. need to check this as i have found slightly different values depending on the timestamps selected. Might be better to take length of data/no. samples Plots y on log scale and x as linear h is the handle to the plot Inputs d: complete data set data: data you want to plot the power spectrum of t_start: start time (in case you only want to plot a subset of the data) t_stop : stop_time all : 1--> if you want to plot all the data plotOption: string of color, etc. act 16/6/2010 : Original version act 3/10/2010 : Changed order of inputs so default is now to plot power power spectrum of all the data mas 3/05/2012 : Added optional loglin parameter to allow for log-linear plots (which are better for the load correction). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [x_power_spec,y_power_spec,h, NFFT]= plot_powerspec(d,data,all,t_start,t_stop, plotOption, loglin) 0002 0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0004 % 0005 % function [x_power_spec,y_power_spec,h, NFFT]= plot_powerspec(d,data,all,t_start,t_stop,plotOption, loglin) 0006 % 0007 % Plots a simple power spectrum of requested data 0008 % 0009 % Takes sample length by looking at difference between adjacent timestamps 0010 % N.B. need to check this as i have found slightly different values 0011 % depending on the timestamps selected. Might be better to take length of 0012 % data/no. samples 0013 % 0014 % Plots y on log scale and x as linear 0015 % h is the handle to the plot 0016 % 0017 % Inputs d: complete data set 0018 % data: data you want to plot the power spectrum of 0019 % t_start: start time (in case you only want to plot a subset of the data) 0020 % t_stop : stop_time 0021 % all : 1--> if you want to plot all the data 0022 % plotOption: string of color, etc. 0023 % 0024 % act 16/6/2010 : Original version 0025 % act 3/10/2010 : Changed order of inputs so default is now to plot power 0026 % power spectrum of all the data 0027 % mas 3/05/2012 : Added optional loglin parameter to allow for log-linear 0028 % plots (which are better for the load correction). 0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0030 0031 if (all==1) 0032 t_start = 1; 0033 t_stop = length(d.antenna0.receiver.utc); 0034 end; 0035 0036 if(nargin<6) 0037 plotOption = 'b'; 0038 end 0039 if(nargin<7) 0040 loglin = 0; 0041 end 0042 0043 t_sec = (d.antenna0.receiver.utc(t_start:t_stop)-d.antenna0.receiver.utc(t_start))*24*60*60; 0044 t_sec = t_sec - t_sec(1); 0045 Fs = 1/(t_sec(3)-t_sec(2)); 0046 L= length(data(t_start:t_stop)); 0047 NFFT = 2^nextpow2(L); 0048 y_power_spec = (fft(data(t_start:t_stop),NFFT)/L); 0049 x_power_spec = Fs/2*linspace(0,1,NFFT/2+1); 0050 0051 if loglin == 0 0052 eval(sprintf('h = loglog(x_power_spec, 2*abs(y_power_spec(1:NFFT/2+1)),''%s'');', plotOption)); 0053 else 0054 eval(sprintf('h = semilogy(x_power_spec, 2*abs(y_power_spec(1:NFFT/2+1)),''%s'');', plotOption)); 0055 end 0056 set(gca,'fontsize',5) 0057 return