Your code has too many unassigned variables for us to execute it. Your FFT freq axis, in radians/sample, goes from 0 –to- 2pi. The equivalent mathematical FFT integer freq axis index goes from 0 –to- 4095. You want to know h1 at w = pi/(2M) radians/sample. Let's use variable k to represent the mathematical FFT integer index corresponding to your w.
So we can set two ratios equal to each other: k/4096 = w/2pi. Next we write k/4096 = (pi/(2M))/2pi. This gives us k = 4096/(4M) = 4096/32 = 128 as the math index corresponding to your w. Because of Matlab's unpleasant indexing method the magnitude response you want to examine is your h1(k+1) = h1(129) FFT sample. [By the way, as long as your M is an integer power of two, k will be an integer. If M is not an integer power of two, you'll have to use either a 'floor()' or 'ceil()' command to compute the mathematical FFT integer index k.]