diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m
index 3cdd4c097ea47997ebba010eca4e26f00c55139e..5f0af2dbdfdc5e2ccb834144031ccb64b9b05e63 100644
--- a/matlab/dynare_estimation_init.m
+++ b/matlab/dynare_estimation_init.m
@@ -671,12 +671,14 @@ if options_.heteroskedastic_filter
 
     for k=1:length(M_.heteroskedastic_shocks.Qvalue_orig)
         v = M_.heteroskedastic_shocks.Qvalue_orig(k);
-        temp_periods=v.periods(v.periods<=options_.nobs+options_.first_obs);
+        temp_periods=v.periods(v.periods<options_.nobs+options_.first_obs);
+        temp_periods=temp_periods(temp_periods>=options_.first_obs);
         M_.heteroskedastic_shocks.Qvalue(v.exo_id, temp_periods-(options_.first_obs-1)) = v.value^2;
     end
     for k=1:length(M_.heteroskedastic_shocks.Qscale_orig)
         v = M_.heteroskedastic_shocks.Qscale_orig(k);
-        temp_periods=v.periods(v.periods<=options_.nobs+options_.first_obs);
+        temp_periods=v.periods(v.periods<options_.nobs+options_.first_obs);
+        temp_periods=temp_periods(temp_periods>=options_.first_obs);
         M_.heteroskedastic_shocks.Qscale(v.exo_id, temp_periods-(options_.first_obs-1)) = v.scale^2;
     end