0
$\begingroup$

I am learning signal processing. For a hobby project I wanted to transmit and record a simple ASK signal via my soundcard, to see if I can write code to recover the sent data. After playback and recording, the recorded signal isn't even close to the original. I thought that the problem was my code, but I could not fix it.

Eventually I tried to play back and record a square wave signal with Audacity. The results of the recording can be seen in the picture. The recorded signal does not look like a square wave. But it sounds the same and the spectra look similar.

enter image description here

Can anyone help me with this problem? How it is possible to record a "real" square wave signal?

$\endgroup$
2
  • 1
    $\begingroup$ Audacity playback (square wave)--> DAC --> audio interface (analog out) --> (loop-back cable) --> audio interface (analog input) --> ADC --> Audacity (recording) ... DAC and ADC are lossy stages so your data gets changed there. You get it lossless only by using digital (loop-back) recording. en.wikipedia.org/wiki/Digital-to-analog_converter , en.wikipedia.org/wiki/Analog-to-digital_converter (you could try subtract square wave from recording (turn phase 180 deg) to get the "error data" and then cancel error from recording using same method). $\endgroup$
    – Juha P
    Aug 23, 2022 at 19:53
  • 1
    $\begingroup$ What is your sample rate? Square waves are made from the linear combination of a fundamental frequency component with an infinite amount of odd harmonics. If your sample rate is too low, you'll be missing the higher harmonics. That and what @JuhaP said. If your purpose is only to see if you can write code to recover the sent data, just start with a simple sine wave... $\endgroup$
    – Jdip
    Aug 23, 2022 at 19:58

2 Answers 2

2
$\begingroup$

This is not a good recording. A lot of things could be happening here, so without knowing your specific details, it's hard to tell.

Some possibilities

  1. You are definitely clipping somewhere in the chain. Your output waveform tops out at 1 the tops are cut off.
  2. I don't know the frequency of your square wave, but there seem to be some significant low-pass filtering going on
  3. There are unusual but repetitive peaks in the wave form. That could be a problem with the buffering or the driver.
  4. Overall the waveform is not as smooth as it should be, which indicates a fair bit of noise.

You need to go step by step through the signal chain and check each individual element.

Some suggestions:

  1. Look at the drivers. ASIO is best, the standard Window Driver are not great. Make sure you set up the buffering so you have a healthy margin before getting drop outs.
  2. Make sure your audio devices are configured properly. The operating system can have a lot of settings (typically "advanced" settings) that modigy the audio. Enhancements, Automatic Gain Control, Spatial processing, etc. Make sure these are all turned off.
  3. Check you gain staging: Make sure you don't overdrive the output or clip the input.
  4. How do you do the loopback. Does it involve a speaker and a microphone (which would make this VERY complicated), or just a cable. Do you have a ground loop? Are the A/D and D/A clocks synced ?
$\endgroup$
1
$\begingroup$

I am the autor of the original question. But for some reason I can't answear properly.

Thank you for your suggestions. I tried them out, but in the end I used an external soundcard. Now it works perfectly.

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ If you tried them out and the answer was satisfactory, please mark it as "accepted" for people that might have the same question in the future! $\endgroup$
    – Jdip
    Aug 24, 2022 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.