Mag Card Emulation / Signal Generation Help

I'm hoping someone will be able to give me some assistance with a problem I've been struggling with for some time. Some time ago I built what amounts to a mag stripe car emulator using a custom generated sound file and driving a coil from my computer sound card. Lately I've been trying to build it all into a stand alone device using an arduino.

I posted some time ago asking for help and since have made some progress since then. I realized that I would need to flip the polarity of the coil to generate the signal which could not accomplished with just the arduino. I am now using a simple h-bridge and two digital outputs to flip the voltage to the coil.

I have been piping the output of the arduino that would normally drive the coil into the microphone input of my computer to view the signal that the arduino is producing and have been comparing it to an audio file I generated previously that successfully allowed me to emulate a mag card.

Unfortunately I can't seen to figure out how to get the signal right. I have included a stripped down version of my code below for readability. The function myBit seems to be very close to what I want, but when generating a zero it has double the peaks it needs. I included another function theBit in which I try to break up the wave form into pieces and piece it together how I think it should be.

For reference I am trying to generate what is called an Aiken Biphase Signal, Differential Manchester encoding - Wikipedia .

Any help would be awesome, this is driving me nuts.

Thanks!

#define ZEROSPEED 1000
#define ONESPEED ZEROSPEED/2  //Ones are represented as twice the frequency of a 0

int outputPin1 = 50;
int outputPin2 = 52;

  
int data[100]; //the data (binary) that is sent to the card emulator



void setup(){

  pinMode(outputPin1, OUTPUT);
  pinMode(outputPin2, OUTPUT);
  
  digitalWrite(outputPin1,LOW);
  digitalWrite(outputPin2,LOW); 




void loop(){
 

  for(i=0; i < 100; i++){ 

    if(data[i]==1){
        myBit(1);
    }

    else if(data[i]==0){
        myBit(0);
    }

  }

  delay(10000);
  
}



//this appears to produce output close to what is needed but its still not right,  it looks like it might be producing double the number of peaks when trying to represent a 0

void mybit(int size) {
 
  digitalWrite(outputPin1, HIGH);
  digitalWrite(outputPin2, LOW);
  delayMicroseconds(size);
  digitalWrite(outputPin1, LOW);
  digitalWrite(outputPin2, HIGH);
  delayMicroseconds(size);
   
}


//  This just never meshes up right

/*
void theBit(int type) {
  
  //might need to add low low after each?
  
  if(type == 0){
    if(toggle == 1){
      digitalWrite(outputPin1, LOW);
      digitalWrite(outputPin2, HIGH);
      delayMicroseconds(ZEROSPEED);
    }
    
    if(toggle == 0){
      digitalWrite(outputPin1, HIGH);
      digitalWrite(outputPin2, LOW);
      delayMicroseconds(ZEROSPEED);
    }
  }
  
  
  if(type == 1){
    if(toggle == 0){
      digitalWrite(outputPin1, LOW);
      digitalWrite(outputPin2, HIGH);
      delayMicroseconds(ONESPEED);
      digitalWrite(outputPin1, HIGH);
      digitalWrite(outputPin2, LOW);
      delayMicroseconds(ONESPEED);
    }
    
    

  
    if(toggle == 1){
      digitalWrite(outputPin1, HIGH);
      digitalWrite(outputPin2, LOW);
      delayMicroseconds(ONESPEED);
      digitalWrite(outputPin1, LOW);
      digitalWrite(outputPin2, HIGH);
      delayMicroseconds(ONESPEED);
    }
  }
  
    toggle = !toggle;

}

*/