0
votes

I have a little problem regarding MATLAB and its syntaxes. I'm trying to plot a spectrum regarding an AM-modulated signal.

In my case the AM-modulation is defined as:

y(t)=[1+m*x(t)]*cos(2*pi*fc*t), where fc=100 kHz and m=0.5

Breaking y(t) in parts:

y(t)=cos(2*pi*fc*t)+m*x(t)*cos(2*pi*fc*t)

and now x(t) is cosine wave with an amplitude of 1 and frequency range from fx=[0-5000Hz]. So y(t) can be written as:

y(t)=cos(2*pi*fc*t)+m*cos(2*pi*fx*t)*cos(2*pi*fc*t)

Using the trigonometric identity, we can write y(t) as:

cos(x)cos(y)=1/2(cos(x-y)+cos(x+y))

y(t)=cos(2*pi*fc*t)+m/2*cos(2*pi*t(fc-fx))+m/2*cos(2*pi*t(fc+fx))

Now when fx=[0,5000Hz], y(t) can be written as the sum of these harmonic waves:

y(t)=cos(2*pi*fc*t)+m/2*cos(2*pi*t(fc-0))+m/2*cos(2*pi*t(fc+0))+m/2*cos(2*pi*t(fc-1))+m/2*cos(2*pi*t(fc+1))... + m/2*cos(2*pi*t(fc-5000))+m/2*cos(2*pi*t(fc+5000))

Now when writing this all down in MATLAB:

clear all;
fc=100000; //base frequency
Fs=250000; //sampling rate should be Fs>2fc according to Nyquist criterion
Ts=1/Fs;
m=0.5;
t = 0:Ts:1-Ts;
fx= 0:1:5000;
yt=cos(2*pi*fc*t)+m*0.5*cos(2*pi*t(fc-fx))+m*0.5*cos(2*pi*t(fc+fx)) // this is where all goes wrong
plot(abs(fft(yt))); // I don't know if this is the correct way to plot it.

The program always states that there's an error in the line with yt, it complains something about matrix dimensions should agree. I really don't know how I can fix this prom, so any help or suggestions are really appreciated.

1
Is there a specific reason that you are not using the ammod function?Scott
Didn't know there was a function ammod before you mentioned it, I have to do some studying regarding it.roneboy

1 Answers

0
votes

The reason why is because the dimensions of t and the dimensions of fx don't match. You need to make sure that both of the dimensions of t and fx match. Therefore, try changing fx to this to ensure that both arrays are the same size:

fx = 0:(numel(t)-1);