function[r] = do_all_lev(n,t0,int,duration,n_N,int_N,n_srate,int_srate,rat,MC_L,MC_F) %do_all_lev 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 graphs the rms of the cost %function vs time. 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. You have the option of filtering MC_L data with acc and seis data or %you can filter MC_F data with mic data by typing 1 or 0 for those inputs. %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 %want to loop over various sample rates and various orders %looping over various orders of filter 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 %--------------------------------------------- %Plotting stuff %plot error vs.N for different times at a given srate (for structure type 3) %if err_srate_time==1 % B=r.B % N_vector=r.B.N % u=size(B(kk).y_s)%(number of N's,number of times) % leg='' % color='bgrcmyk' % %looping over N's to make vectors to graph with % for ll=1:u(1) % q_temp=B(kk).y_s(ll,:) % if ll==1 % q=q_temp % else % q=[q;q_temp] % end % end %looping over times % for ll=1:u(2) % plot(N_vector,q(:,ll),color(1+mod(ll-1,7))) % hold on % if ll>9 % b='' % else % b='0' % end % leg_temp=['time' b num2str(ll)] % leg=[leg; leg_temp] % end % hold off % ylabel('max rms error(cts/rHz)') % xlabel('srate(Hz)') % ti=['error vs srate for different times N=' num2str(r.B(kk).N(kk))] % title(ti) % legend(leg) %end %err vs N for diff times at given srate %if err_N_time==1 % B=r.B % N_vector=r.N_vector % v=size(B) % v=v(2)%number of srate's % u=size(B(kk).y_s)%(number of N's,number of times) % leg='' % color='bgrcmyk' %looping over srate's to make vectors to graph with % for ll=1:v % q_temp=B(ll).y_s(kk,:) % if ll==1 % q=q_temp % else % q=[q;q_temp] % end % end %looping over times % for ll=1:u(2) % plot(N_vector,q(:,ll),color(1+mod(ll-1,7))) % hold on % if ll>9 % b='' % else % b='0' % end % leg_temp=['time' b num2str(ll)] % leg=[leg; leg_temp] % end % hold off % ylabel('max rms error(cts/rHz)') % xlabel('srate(Hz)') % ti=['error vs srate for different times N=' num2str(r.B(kk).N(kk))] % title(ti) % legend(leg) %The following doesn't yet work err vs N for diff times %if err_time_N==1 % B=r256L.B % N_vector=r256L.N_vector % u=size(B(kk).y_s) % leg='' % color='bgrcmyk' %looping over N's % for ll=1:length(N_vector) % q_temp=B(ll).y_s(kk,:) % if ll==1 % q=q_temp % else % q=[q;q_temp] % end % end %looping over times % for ll=1:u(2) % plot(N_vector,q(:,ll),color(1+mod(ll,8))) % leg_temp=['time' num2str(ll)] % leg=[leg; leg_temp] % hold on % end % hold off % legend([leg]) % ylabel('max rms error(cts/rHz)') % xlabel('N(order)') % title(['error vs N for different times srate=' num2str(r.B(1).s_s(kk))]) %end %plot(N_vector,q1,N_vector,q2,N_vector,q3,N_vector,q4,N_vector,q5,N_vector,q6,N_vector,q7)if %err_time_N==1 %err vs N for different srates % B=r256L.B % N_vector=r256L.N_vector % u=size(B(kk).y_s) % leg='' % color='bgrcmyk' %looping over N's % for ll=1:length(N_vector) % for ll=1:5 % q_temp=B(ll).y_s(:,kk) % if ll==1 % q=q_temp' % else % q=[q;q_temp'] % end % end %looping over srates % for ll=1:u(1) % %plot(N_vector,q(:,ll),color(1+mod(ll,8))) % temp_srate=B(kk).s_s(ll) % plot(N_vector(1:5),q(:,ll),color(1+mod(ll,8))) % if ll==1 % t='0' % else % t='' % end % leg_temp=['srate ' t num2str(B(kk).s_s(ll)) 'Hz'] % leg=[leg; leg_temp] % hold on % end % hold off % legend([leg]) % ylabel('max rms error(cts/rHz)') % xlabel('N(order)') % title(['error vs N for different srates, time1']) %end %plot err vs IR for different srates % B=r256L.B % N_vector=r256L.N_vector % u=size(B(kk).y_s) % leg='' % color='bgrcmyk' %looping over N's % for ll=1:length(N_vector) % for ll=1:5 % q_temp=B(ll).y_s(:,kk) % if ll==1 % q=q_temp' % else % q=[q;q_temp'] % end % end %looping over srates % for ll=1:u(1) %plot(N_vector,q(:,ll),color(1+mod(ll,8))) % temp_srate=B(kk).s_s(ll) % plot((N_vector(1:5)*(1/temp_srate)),q(:,ll),color(1+mod(ll,8))) % if ll==1 % t='0' % else % t='' % end % leg_temp=['srate ' t num2str(temp_srate) 'Hz'] % leg=[leg; leg_temp] % hold on % end % hold off % legend([leg]) % ylabel('max rms error(cts/rHz)') % xlabel('Impulse Response(seconds)') % title(['error vs IR for different srates, time1']) %end