How can i get a similar AM waveform?

Hi everyone. Basically, i am generating a ".wav" file using the code below in MATLAB

Fs = 14400; 
duration = 20;
t = linspace(0 , duration , duration*Fs );

m = cos(2*pi*10*t);
A = 1.5;
f_c = 200;
s = (A + m).*cos(2*pi*f_c*t);
s = s / max(s);
% sound(s, Fs);
audiowrite("deneme.wav", s, Fs);

I have a voltage divider circuit to shift this waveform. I am giving the ".wav" file as an input to this circuit, and getting an shifted output from A0 pin of the arduino. And using arduino USB cable and the following code, I am sending it to the computer, using the arduino code below.

int sensorValue = 0; 

void setup () 

void loop ()
  sensorValue = analogRead(0); 
  sensorValue = sensorValue / 4; 

Then, in MATLAB, I am trying to plot the shifted version of the wave form again using the following code.

priorports = instrfind;
s = serial('COM4');

s.InputBufferSize = 1000; 

set(s, "BaudRate", 115200); 
while 1 




But as a result i am getting this weird waveform. I want it to be a normal looking AM wave, but it turns out to be like this:


What am I doing wrong? Thanks in advance.

If you plot points instead of lines you may notice that analogRead() happens to take at most 4 samples from a full wave.

Get a faster ADC or lower carrier frequency.

Thanks for your reply. Before seeing your comment, I changed the resistors in my voltage divider circuit from 100 ohm to 100k ohm, and the problem has been resolved. Then this is now what the wave looks like:


Normally, as long as identical resistors are used, resistance value shouldn't matter. I don't know what the reason is. What is your opinion?

Nobody can give a good opinion without seeing your circuit schematic. "identical resistors" in a completely unknown circuit, is completely meaningless.

I was using this circuit:

But instead of 22kohm resistors, I used 100 ohm.

I asked this to a teaching assistant. He said:

Since you used small valued resistors, the time constant becomes very small, and capacitor charges and discharges very fast. Therefore, ac coupling cannot be done efficiently.

I think the problem has been resolved. Thank you all.

Good teaching assistant.

1 Like

Yes it matters very much. Not for the division ratio but for the over all impedance of the load that the potential divider presents to the voltage source.
Using such low values means that the voltage source has to supply a lot more current to the divider than it would have to do if the absolute values were to be a lot higher.

1 Like

Say you'd used 0.000000001 ohm resistors - would you expect that to work too? I hope not...

You were simply overloading your amp, whatever that was, and greatly reducing the amplitude to a few LSBs of the ADC, giving a steppy output.

Ironically you didn't post any details of the hardware so we'd not have been able to figure things out for you (that's why posting everything (code, hardware details, circuit, photo) is a great idea if you want a quick solution - many eyes over everything usually spot the problem).

Yeah you are right. I just wanted to simplify the things but the simplification might cost a lot. I should be all transparent from now on.

In low voltage solid state circuitry 100 ohms is generally thought of as low, 1M is high, and the normal range is 1k..100k for many purposes (opamps, pullups, voltage dividers, etc). The underlying reason is that as you get below 100 ohms or so power dissipation becomes important, and above 100k noise-pickup starts to become important.

However at higher frequencies things change, much RF stuff is 50 ohms and 1k is a high value!