Frequency modulation of $m(t)$ in MATLAB I have a message signal defined in the below interval
$$
m(t)=\begin{cases}1&amp;, 0\leq t &lt; \frac{t_0}{3}\\[2ex]
-2&amp;, \frac{t_0}{3}\leq t &lt;\frac{2t_0}{3}\\[2ex]
0&amp;, \frac{2t_0}{3}\leq t &lt; t_0\end{cases}
$$

where $t_0 = 0.15\ \rm seconds$, and sampling frequency $F_s=2\ \rm kHz$.

My MATLAB code in order to construct $m(t)$

t0= 0.15;
Fs= 2000;
t1= 0:1/Fs:t0/3- 1/Fs;
t2= t0/3:1/Fs:2*t0/3 - 1/Fs;
t3= 2*t0/3:1/Fs:3*t0/3-1/Fs;
m1= ones([1, length(t1)]);
m2= -2*ones([1, length(t2)]);
m3= zeros([1, length(t3)]);
m= [m1, m2, m3];
t= [t1, t2, t3]; 


I'm trying to find frequency modulation and the following formula is wanted to be used
$$
x_{FM}(t) = \cos\left(2 \pi  f_c t + 2\pi  k_f \int_{-\infty}^t m(x) dx\right)
$$
with carrier frequency $f_c=200$Hz and deviation constant $k_f= 50$.

Only for or while loops are allowed while we find integral. In order to integrate, I have made this for loop

result=0;
j=1;

for i= 0:1/Fs:t0- 1/Fs
   result= result + m(j);

    %% result2 will be used as we integrate it over 0 to 0.15
   result2(j) = result;
   j= j+1;
end


Please tell me, is something wrong with this integration?
I plotted this and it seems correct to me. 



If the integration is true, then why frequency didn't change at all when plotting this signal.

xFM= cos(2*pi*fc*t + 2*pi*kf*result)




Full code here
Integration was incorrect. I was integrating it with $dx= 1$. Doing m(j)*1/Fsoperation in the for loop, I have made $dx= 1/Fs$ now.

As can be seen, frequency changes for different amplitudes now.


Moreover, resultis a constant, it should be changed toresult2 so that it gives result with respect to time $t$.