function[r] = do_all_time_lev(n,t0,int,duration,N,srate,rat,order,time,MC_L,MC_F,sample_rate) %do_all_time explores how filter performance changes with time, sample rate, %and order of filter. Outputs data,noise estimate, structure of max %rms error and other info. It uses get_data, miso_filter_lev, and miso_filter_int and retrives %MC_Ldata or MC_Fdata for multiple times, calculates a miso_filter for initial-time data %file, applies filter to the other data files, and keeps track of the... %max(rms(residual)) for each filter. n+1 is number of data files. int is time interval between %data files, t0 is start time, duration is duration of each data file, srate %is the sample rate for which filter is calculated, n_N is number of orders %of the filter you want the program to calculate,int_N is interval by which N %is varied, n_N is number of srates you want the program to calculate filters %for, srate will be varied as sample_rate_temp=2^(6+j*int_srate) where j-integer, %rat is the fraction of the initial data file which is used to calculate %filter. Maybe let n=6 because I not sure I haven't figured out how to fix miso_filter_int to %work for variable n. You have the option of varying the order, the time, and %srate by typing 1 or 0 for those inputs. %function[r] = do_all_time_lev(n,t0,int,duration,n_N,int_N,n_srate,int_srate,rat,MC_L,MC_F) time=1 if time==1 %getting data for each time and storing in vector z for ii = 0:n d_t = -ii*int; if MC_L==1 z_temp = get_z_data(t0,d_t,duration); end if MC_F==1 z_temp = get_mic_data(t0,d_t,duration); end if ii == 0 z = z_temp; else z = [z ; z_temp]; end clear d_t z_temp; end else z=get_mic_data(t0,0,duration); end %calculate miso_filter based on initial data file %calculating filters for case of not varying order and for case of varying order if order+sample_rate==0 w = miso_filter(N,srate,rat,z(1,:)); %applying filter to data files at all the other times s = miso_filter_int(w,z(2:n+1,:)); %calculating rms of error=singal-est_signal for each file and creating %rms vector and time vector to graph x = 0; y = 0; %looping over various times for gg=1:n+1 x_temp = s.t(1,gg); x = [x,x_temp]; y_temp = max(rms(s.f(:,gg),s.perr(:,gg))); y = [y, y_temp]; clear x_temp y_temp end clear gg %getting rid of zeroes in x and y row vectors x = x(2:end) y = y(2:end) %graphing rms of error vs time plot(x,y); xlabel('time(gps)') ylabel('cts/rHz') title('filter performance over time') legend('rms of cost function') B=struct('x_s',x,'y_s',y,'s_s',srate,'N',N) r=struct('z',z,'B',B,'N_vector',N) %_______________________________ elseif sample_rate==0 %looping over various orders of filter for kk=0:20 % N_temp=2^(8+kk); N_temp=floor(2^(8+(kk/4))) w_temp = miso_filter_lev(N_temp,srate,rat,z(1,:)); %applying filter to data files at all the other times s_temp = miso_filter_int(w_temp,z(2:n+1,:)); %calculating rms of error=singal-est_signal for each file and creating %rms vector and time vector to graph x = 0; y = 0; %looping over various times for gg=1:n+1 x_temp = s_temp.t(1,gg); x = [x,x_temp]; y_temp = max(rms(s_temp.f(:,gg),s_temp.perr(:,gg))); y = [y, y_temp]; clear x_temp y_temp end clear gg %getting rid of zeroes in x and y row vectors x = x(2:end); y = y(2:end); %storing x and y row vectors as rows in matrices x_n, y_n. Also creating row %vector for corresponding N's. if kk==0 x_n = x y_n = y N_n = N_temp else x_n = [x_n;x]; y_n = [y_n;y]; N_n = [N_n;N_temp] end %clearing variables before looping again clear N_temp x y w_temp s_temp B=struct('x_n',x_n,'y_n',y_n,'s',srate,'N_n',N_n) r=struct('z',z,'B',B,'N_vector',N_n) end %____________________________ elseif order==0 %looping over various sample rates for filter for jj=0:3 sample_rate_temp=2^(6+jj); w_temp = miso_filter_lev(N,sample_rate_temp,rat,z(1,:)); %applying filter to data files at all the other times s_temp = miso_filter_int(w_temp,z(2:n+1,:)); %calculating rms of error=singal-est_signal for each file and creating %rms vector and time vector to graph x = 0; y = 0; %looping over various times for gg=1:n+1 x_temp = s_temp.t(1,gg); x = [x,x_temp]; y_temp = max(rms(s_temp.f(:,gg),s_temp.perr(:,gg))); y = [y, y_temp]; clear x_temp y_temp end clear gg %getting rid of zeroes in x and y row vectors x = x(2:end); y = y(2:end); %storing x and y row vectors as rows in matrices x_s, y_s. Also creating row %vector for corresponding sample_rate's. if kk==0 x_s = x y_s = y s_s = sample_rate_temp else x_s = [x_s;x]; y_s = [y_s;y]; s_s = [s_s;sample_rate_temp] end %clearing variables before looping again clear s_temp x y w_temp sample_rate_temp B=struct('x_s',x_s,'y_s',y_s,'s_s',s_s,'N',N) r=struct('z',z,'B',B,'N_vector',N) end %_________________________ else %want to loop over various sample rates and various orders %looping over various orders of filter n_N=19 int_N=100 n_srate=2 int_srate=1 for kk=0:n_N-1 %looping over various sample rates for filter %N_temp=2^(8+kk); N_temp=(2^8)+kk*int_N for jj=0:n_srate-1 sample_rate_temp=2^(6+jj*int_srate); w_temp = miso_filter_lev(N_temp,sample_rate_temp,rat,z(1,:)); %applying filter to data files at all the other times s_temp = miso_filter_int(w_temp,z(2:n+1,:)); %calculating rms of error=singal-est_signal for each file and creating %rms vector and time vector to graph x = 0; y = 0; %looping over various times for gg=1:n+1 x_temp = s_temp.t(1,gg); x = [x,x_temp]; y_temp = max(rms(s_temp.f(:,gg),s_temp.perr(:,gg))); y = [y, y_temp]; clear x_temp y_temp end clear gg %getting rid of zeroes in x and y row vectors x = x(2:end); y = y(2:end); %storing x and y row vectors as rows in matrices x_s, y_s. Also creating column %vector for corresponding sample rates. if jj==0 x_s = x y_s = y s_s = sample_rate_temp else x_s = [x_s;x]; y_s = [y_s;y]; s_s = [s_s;sample_rate_temp]; end %clearing variables before looping again clear sample_rate_temp x y w_temp s_temp end %want to store the matrices x_s y_s and s_s for each successive iteration of %N. one could create a structure for the matrices. Use structure called %B. Also create a vector of B.N to graph with. B_temp = struct('x_s',x_s,'y_s',y_s,'s_s',s_s,'N',N_temp); if kk==0 B = B_temp; else B = [B,B_temp]; end %create a column vector of B.N to graph with. for ii=1:length(B) if ii==1 N_vector = B(ii).N; else N_vector = [N_vector;B(ii).N]; end end r=struct('z',z,'B',B,'N_vector',N_vector) end end