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
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
result2
when calculatingxFM
?result
is a constant. $\endgroup$result
is a constant by the time you use it.result2
contains the integral from 0 toj/Fs
in indexj
. What is the maximum value ofkf*result2
? Maybe your frequency deviation is very small and that's the reason you don't see it in your plot. $\endgroup$