the dominant frequency is overwritten in every iteration using matlab code
You are searching for the maximum on the entire epoched/windowed data-set:

[v,k] = max(datax);


getting the value and index to this maximum. However you should restrict your search on the frequencies of interest:

valid_idx=(freq&gt;=0.1 &amp; freq&lt;=2);
[v,k] = max(datax(valid_idx));


I would leave the find out as you can perform the search on a logical-index variable and thus you do not need to transform the found-index into the original index.

Additionally, I would first demean your data:

data_x = currentwindow_sigx-mean(currentwindow_sigx);


Which would be equal to detrend(currentwindow_sigx,'constant'), without the parameter constant you are detrending and not demeaning. After this I would apply the hamming window. And then calculate the fft.
You should inspect your data afterwards and check if the data looks "physiological", especially in the frequency band of interest. Here you need some experience to judge this. If the data looks okay the maximum search should give you the correct result. 

I assume that the fft will be noise, you could apply some smoothing to it before you search for the dominat frequency to avoid outliers.