Hi there! Have some new code based on Matlab. It was actually a Computer Exercise for my Telecom course. It is an example of Amplitude Modulation of a Cos based message. The code is easy enough. If you have any questions please ask. Hope you enjoy it.

function am_modulation

N=2000;
F=(-N/2:N/2-1)/N;

user_entry1 = input('Please enter carrier freq [Press enter for default fc=0.25] :');
if isempty(user_entry1)
    fc=0.25;
else
    fc=user_entry1;
end

user_entry4 = input('Please enter amplitude of carrier wave [Press enter for default Ac=1] :');
if isempty(user_entry4)
    Ac=1;
else
    Ac=user_entry4;
end

n=0:1:256;

c=Ac*cos(2*pi*n*fc);
subplot(2,2,1)
plot(F, fftshift(abs(fft(c,N))));
title('Carrier Wave at frequency-domain');
xlabel('frequency'), ylabel('amplitude');
grid on;



user_entry2 = input('Please enter message freq [Press enter for default fm=0.01] :');
if isempty(user_entry2)
    fm=0.01;
else
    fm=user_entry2;
end

user_entry5 = input('Please enter message amplitude [Press enter for default Am=1] :');
if isempty(user_entry5)
    Am=1;
else
    Am=user_entry5;
end

m=Am*cos(2*pi*fm*n);
subplot(2,2,2)
plot(F, fftshift(abs(fft(m,N))));
title('Message at frequency-domain');
xlabel('frequency'), ylabel('amplitude');
grid on;


user_entry3 = input('Please enter amplitude sensitivity cnst. [Press enter for default ka=0.5] :');
if isempty(user_entry3)
    ka=0.5;
else
    ka=user_entry3;
end

s=(1+m.*ka).*c;

subplot(2,2,[3 4])
plot(F,fftshift(abs(fft(s,N))));
title('AM waveform at frequency-domain');
xlabel('frequency'), ylabel('amplitude');
grid on;

Here is an example result of the code ;

Amplitude Modulation of a cosine message