سؤال

I'm trying to modulate a signal in MatLab by multiplying some signal with a carrier signal. The carrier signal is cos(2*pi*fc*t) and this is my code so far

for t = 1:length(input);  
      m(t) = (Ac + input(t)).*cos(2*pi.*fc.*t);
end
xam = m;

input, Ac and fc are parameters that need to be entered when using the function. When I run this code with any input signal (I've been using cos(t) with t = 0:0.001:10) the output is always the same signal. However if I use ./ instead of .* in front of the fc, the output is modulated. Why does using .*fc instead of ./fc not work?

هل كانت مفيدة؟

المحلول

For starters, you can vectorize your equation like so:

t = 0:0.001:10;
input = cos(t);
xam = (Ac + input).*cos(2*pi*fc*(1:length(t)));

I suspect that the reason you are seeing the exact same output curve each time is that your fc value is an integer. If fc is an integer, cos(2*pi*fc*t) evaluates to 1 for all integer values of t, leaving the input signal unchanged after modulation. When you use 1/fc you get a non-integral value and the output is modulated.

I believe what you want to do is the following:

t = 0:0.001:10; % Time in seconds
f = 1; % Frequency of input signal in rad/s
fc = 3; % Frequency of carrier wave in rad/s
input = cos(2*pi*f*t); % Input signal
xam = (Ac + input).*cos(2*pi*fc*t); % Amplitude modulated signal

The comments show the meaning of each argument. If you only wanted to pass the sampling rate fs into your function, the solution would look like this:

N = 1001;
fs = 1000;
t = (0:1:N)*(1/fs);
f = 1;
fc = 3;
input = cos(2*pi*f*t);

And your function would look like so:

function xam = modulate(input, fs, fc, Ac) 
    t = (0:1:length(input))*(1/fs);
    xam = (Ac + input).*cos(2*pi*fc*t);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top