invert phase audio signal

Status
Not open for further replies.

fred_france

Active member
Hello,

I would like to reverse the phase of the audio signal (180 °) to experiment around the cancellation of sounds.

I tried with a mixer to set the gain to -1 (i tried too with the amp), but the signals are not inverted as shown in the oscillogram.
(sine signal 2K700hz 1vp-p, red : input, blue : ouptut).

if i change the frequency, the offset between input and output changes, but is never 180 degrees

invert_phase.jpg

my code :
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s2;           //xy=214,235
AudioMixer4              mixer1;         //xy=547,366
AudioOutputI2S           i2s1;           //xy=879,224
AudioConnection          patchCord1(i2s2, 0, mixer1, 0);
AudioConnection          patchCord2(mixer1, 0, i2s1, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=857,517
// GUItool: end automatically generated code



const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;

void setup() {
  // put your setup code here, to run once:
  AudioMemory(50);
  // Enable the audio shield. select input. and enable output

  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(myInput);
  sgtl5000_1.volume(0.4); // 

  mixer1.gain(0,-1);
  mixer1.gain(1,0);
  mixer1.gain(2,0);
  mixer1.gain(2,0);  
}

void loop() {
  // put your main code here, to run repeatedly:

}

Do you know if there is another way?

thanks in advance

Fred (Teensy v4.0+ audio Adapter)
 
if you insert an audio object then you have to consider a 128 sample delay.
So, insert two mixers in parallel one with +1 and the other with -1, then you should get the desired effect
 
if you insert an audio object then you have to consider a 128 sample delay.
So, insert two mixers in parallel one with +1 and the other with -1, then you should get the desired effect

if I understand correctly, I put an audio object (microphone), connected to a delay object, then then two mixers?
 
no, I was suggesting
i2s ->mixer (+1) -> I2S left
|-> mixer (-1) -> I2S right
so left and right path have same internal delays
 
I understand the 1st line connection, but I’m not sure for the 2nd : what is «*I*» on the 2nd line ?
(Sorry I’m a newbie).

I only have one audio source (microphone or low frequency generator)
 
sorry about formating
here is the audio code
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=182.0023956298828,239.00240325927734
AudioAmplifier           amp1;           //xy=375.0023880004883,195.00239181518555
AudioAmplifier           amp2;           //xy=377.002384185791,256.0023946762085
AudioOutputI2S           i2s2;           //xy=573.0023956298828,217.00240325927734
AudioConnection          patchCord1(i2s1, 0, amp1, 0);
AudioConnection          patchCord2(i2s1, 1, amp2, 0);
AudioConnection          patchCord3(amp1, 0, i2s2, 0);
AudioConnection          patchCord4(amp2, 0, i2s2, 1);
// GUItool: end automatically generated code
I use amp instead of mixer; amp1 is to be set gain +1, and amp2 is gain -1
you can copy and import the above lines into audio gui to see what I mean.
 
screen3.jpg

ok, now can you tell me :
- where i connect my audio signal (sinusoidale 1khz with an external generator) : left or right or both line in ?
- where i connect my oscilloscope : left or right line out ?

thanks
 
View attachment 23180

ok, now can you tell me :
- where i connect my audio signal (sinusoidale 1khz with an external generator) : left or right or both line in ?
- where i connect my oscilloscope : left or right line out ?

thanks

the way it is wired now, connect audio signal to both line in and oscilloscope channel 1 to ,say, left and channel 2 to right
you could simplify, by connecting both amp inputs to same i2s input channel (left or right)
 
By connecting the two channels of the oscilloscope on L and R of line Out, it works well, the signals are well opposite at 180 ° (see the image below)

screen_5.jpg

But if I plug in the oscilloscope like this:
- oscillo channel 1: on the input (on the sine generator)
- oscillo channel 2: on one of the LineOut outputs
> the signals are out of phase but not at 180 ° (same as what i show in my post #1)

I think there is a processing time which makes it impossible to reverse the input signal in real time
Am I clear in my explanation?
 
But if I plug in the oscilloscope like this:
- oscillo channel 1: on the input (on the sine generator)
- oscillo channel 2: on one of the LineOut outputs
> the signals are out of phase but not at 180 ° (same as what i show in my post #1)

I think there is a processing time which makes it impossible to reverse the input signal in real time
Am I clear in my explanation?

They cannot be 180 deg out of phase. there is a fixed travel time through the audio library
Output is NEVER without delay to input.

AFAIK
I2S-input: data are buffered for 128 samples (2.9 ms @44.1 kHz)
Amp: process data block-wise (another 2.9 ms)
I2S-output: buffered data are output (no further delay)

But you can mesure with oscilloscope

The way your picture is made, both data streams are delayed the same amount of time but one is flipped, so you get the desired result.
 
The way your picture is made, both data streams are delayed the same amount of time but one is flipped, so you get the desired result.

He is trying to experiment with NOISE CANCELLING. Broadcasting an inverted signal in an attempt to cancel out ambient noise.
Due to the inevitable processing delay, will not work by playing output through a speaker to cancel ambient noise.
Lotus played round with this about 10 years ago. Not sure how successful they were.

Will work if used for a headphone where ambient and cancel signal are both delayed by the same or similar amount.
Of course the headphones need to be isolated from ambient noise otherwise a sort of echo might ensue.

On the other hand just isolate the headphones from the environment (over ear headphones) and play whatever you want to through headphones.
 
Thank you for your answers
is it not possible to reduce the processing time of 2.9 ms by reducing for example the bandwidth? (for example: 200hz- 2khz instead of 20hz-20khz)?
 
Thank you for your answers
is it not possible to reduce the processing time of 2.9 ms by reducing for example the bandwidth? (for example: 200hz- 2khz instead of 20hz-20khz)?
The 2.9 ms is result of acquisition buffer (128 samples) and sampling rate (44.1 kHz) so you must change one of the two values to change the delay.
This requires changing some basic parameters. It can be done, but not sure if it brings you forward.

What ever you do in synchron parallel audio processing (one channel straight, other channel phase shifted), you must make sure that parallel paths have same delay.
 
If your *only* goal is to create an inverted audio signal [and no other processing], then I would go for opamps.
See here for basic circuits. One inverting opamp and one non-inverting opamp and feed them both with the same input signal.
With a high-speed opamp you end up with an input-to-output delay in the sub-microsecond range.

Paul
 
yes I saw that there is a lot of electronic diagram with the op amps, I will look at that.

thank you all very much for your help and your time
 
Status
Not open for further replies.
Back
Top