Amplitude-Modulation (AM) with the Arduino

Dear Arduino community,

For my final exams in school I am writing about data-transfer - especially about amplitude-modulated signals.
Now I run into troubles programming my Arduino...

AM modulation is described with the formula:

AM=(A+Input)cos(xt)

AM ... Signal to send
A ... a constant number (the cos() can only be between -1 and 1; by having this "A" in the formula, the AM signal can't get 0)
Input ... is the Signal (unmodulated)
cos(x*t) ... the cos depending on the time; and "x" is a value, that regulates the ground frequency

I haven't used the Arduino for quiet a while and have tried everything I could think of to make this work, but it didn't work out.

I would really appreciate it, if anyone could help me with my problem :wink:

Best regards

BerndR

AM-Signal.pdf (193 KB)

AM modulation is described with the formula:

Your formula isn't correct. Have a look at the section "Simplified analysis of standard AM" in the wikipedia page on amplitude modulation.

by having this "A" in the formula, the AM signal can't get 0

That does not do what you claim at all. If cos(x*t) is zero then so is (A+Input)cos(xt).

have tried everything I could think of to make this work

What exactly have you tried? How do you know it isn't working?

Pete

How do you propose amplitude modulation with a 0 or 5V output signal?
Best you can do is lowpass filter a PWM output to make it look ACish.
Or use an external DAC to create DC levels that you can control, from simple R-2R ladder to parallel/I2C/SPI interface DAC ICs.

Please post one or more of your attempts to code this for the Arduino.
Where does the input come from and where does the output go to ?

Dear Pete,
Thank's for your response.

And I just had a look at the Wiki article you linked me to, but I don't actually know how they achieve the modulation... But I Know for sure, that my formula works as well.

And you are right, the signal can can get 0. But what I meant was, that if there is no input signal, you still have an amplitude at the cos-function.

And to the things I have tried...
The goal of all of this is to have a song AM modulated - this AM-Signal should then be transferred over an LED to a solar panel there the signal gets demodulated again and you can listen to it.
By now, everything works, but not the AM-modulation.
And if the modulation would work, I could send multiple signals to the same solar cell and switch afterwards which information (song) I want to receive.


int Signal;
int A=2; //Wert
int t=0;

void setup(){

pinMode(4, OUTPUT);

}

void loop(){

analogWrite(4, AMSignal()); //Pin suchen
t++;

}

}

int AMSignal(){

int AM;

Signal=analogRead(5); //Pin suchen

AM=(A+Signal)cos(1000t);
return AM;

}


Thats the code I started with... I tried to use digitalRead and Write, analogRead and Write and PWM... but my programming skills are pretty bad (I even had help with this code).

And to check the result I am analyzing the signal with a oscilloscope... but until now i wasn't even able to change the base frequent (the cos() part)

Bernd

CrossRoads:
How do you propose amplitude modulation with a 0 or 5V output signal?
Best you can do is lowpass filter a PWM output to make it look ACish.
Or use an external DAC to create DC levels that you can control, from simple R-2R ladder to parallel/I2C/SPI interface DAC ICs.

I wanted to try it with PWM.
And it doesn't matter, if the signal is DC, because I add a constant DC voltage anyway, to send the signal over an LED. Otherwise the LED would cut off the negative parts.

UKHeliBob:
Please post one or more of your attempts to code this for the Arduino.
Where does the input come from and where does the output go to ?

I have posted a sample of what I have tried in a previous post... (you commented while I was writing ;))
and the Input comes form an MP3 Player (the cable is modified so that I have 2 cables that I connect to the Arduino... I don't know where, but I thought that I should connect them to the Analog Input Pins.)
And the output goes to an amplifier that adapts the signal and applies it to the circuit with the LED.

I would speed things up, go in-line with the code:

int Signal;
int A=2;  //Wert
int t=0;
int AM;

void setup(){

 pinMode(4, OUTPUT);

}


void loop(){

while(1){
 Signal=analogRead(5); //Pin suchen
 
 AM=(A+Signal)*cos(1000*t);
 analogWrite(4, AMSignal());  //Pin suchen
 t++;

 
 }
 
}

Thats the entire setup

CrossRoads:
I would speed things up, go in-line with the code:

int Signal;

int A=2;  //Wert
int t=0;
int AM;

void setup(){

pinMode(4, OUTPUT);

}

void loop(){

while(1){
Signal=analogRead(5); //Pin suchen

AM=(A+Signal)cos(1000t);
analogWrite(4, AMSignal());  //Pin suchen
t++;

}

}

Thanks for this code.
But something is odd... Somehow the formula is applied wrong. I don't know why, but this formula has to have constant frequency and a changing amplitude.

BUT right now, I have a signal generator as Input signal instead of the MP3 player... so I can set the frequency. But by changing the Frequency to the input signal, not the amplitude of the output signal is changed! the frequency os changed!
And that is mathematically incorrect.

[A lot of my rubbish edited out]

But your code is rubbish.

  • it doesn't compile.
  • what is the point of a cosine function which is evaluated at 0, 1000, 2000, 3000, 4000, etc. radians?
  • what is the point of setting A to 2?

Pete

@BerndR: My apologies. I have realized what your formula does - your explanation of it was confused and confusing (at least to my tiny mind). It does do amplitude modulation (under certain conditions) but not the way you've implemented it in your code.

Pete

I think CrossRoads meant the following, but negative values are not supported by analogWrite

Signal=analogRead(5); //Pin suchen
  AM=(A+Signal)*cos(1000*t);
 analogWrite(4, AM);  //was AMSignal()
 t++;

If you constrain AM to be a number between -127 and 128, and add 127 so that the range is between 0 and 255, then you can output the result directly via analogWrite.

Hi

I would have thought

AM=(A+Signal)cos(1000t);

should be

AM=A+(Signalcos(1000t));

because your Signal will always be positive.

The A offset remains constant.

As long as signal < A/2 you will always have a positive value.

The first equation, will always go negative when the cos goes negative because A is MULTIPLIED

  • along with the signal.*

Try both in EXcell.

Tom.... :slight_smile:

Don't forget its Cos of Radians.

The OP has the correct formula for amplitude modulation, (A+signal)cos(ft), where signal is a function of time, but forgot the constant offset required for PWM.

In amplitude modulation there are two amplitudes, the constant carrier wave amplitude A and the modulating time variable amplitude represented by "signal". The time average of the modulated signal is zero.

Hi, I agree but the OP definition.

A ... a constant number (the cos() can only be between -1 and 1; by having this "A" in the formula, the AM signal can't get 0)

I understand this to be the offset needed to stop any result <0.

Tom.... :slight_smile: