I have a message signal defined in the below interval $$ m(t)=\begin{cases}1&, 0\leq t < \frac{t_0}{3}\\[2ex] -2&, \frac{t_0}{3}\leq t <\frac{2t_0}{3}\\[2ex] 0&, \frac{2t_0}{3}\leq t < 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


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;

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

enter image description here

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)

enter image description here

Full code here

  • $\begingroup$ Shouldn't you be using result2 when calculating xFM? result is a constant. $\endgroup$
    – MBaz
    Apr 2, 2018 at 19:11
  • $\begingroup$ I don't know. I tried but it didn't change. Couldn't it be constant because when we take integral of message signal from 0 to 0.15s, it would be constant $\endgroup$ Apr 2, 2018 at 19:37
  • $\begingroup$ result is a constant by the time you use it. result2 contains the integral from 0 to j/Fs in index j. What is the maximum value of kf*result2? Maybe your frequency deviation is very small and that's the reason you don't see it in your plot. $\endgroup$
    – MBaz
    Apr 2, 2018 at 19:58
  • 1
    $\begingroup$ Problem solved when I took dx interval 1/Fs because I used to integrate it with dx= 1 before. And I also had to change result to result2..Thanks $\endgroup$ Apr 3, 2018 at 9:42
  • 1
    $\begingroup$ @UygarUçar do you think you can post this as an answer and accept it too, so that we can close this question gracefully? Otherwise, it will keep circulating in the board as unanswered. $\endgroup$
    – A_A
    Apr 4, 2018 at 8:48

1 Answer 1


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. enter image description here

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

  • $\begingroup$ In a day or so, when the system lets you, please mark this as the accepted answer. $\endgroup$
    – Peter K.
    Apr 4, 2018 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.