gps logger 10hz

Hi everyone, I have a little proyect for making a gps logger, so far I have set the venus gps at 10hz and I succesfull meke a sketch for log the information to a sd shiel. However it has a little problem, sometimes it logs the information with strange characters.
Here es the sketch.

#include <SD.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include "I2Cdev.h"
#include "MPU6050.h"

SoftwareSerial gpsSerial(6, 5); // RX, TX (TX not used)
const int sentenceSize = 312;
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

char sentence[sentenceSize];

#define LOG_INTERVAL 100

const int chipSelect = 10;
File logfile;
long idd = 0;
long ids = 0;
long idm = 0;
long idh = 0;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);

  while(1);
}

void setup()
{
  Wire.begin();
  Serial.begin(38400);
  gpsSerial.begin(38400);
  
  Serial.println("Iniciando MPU");
  accelgyro.initialize();
  Serial.println("Iniciando SD");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Fallo de SD");
    return;
  }
  Serial.println("Inicio Correcto");
  Serial.println("Testeando MPU");
  Serial.println(accelgyro.testConnection() ? "Conexion MPU6050 exitosa" : "Error de Conexion a MPU");
  
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);
}

void loop()
{  
  static int i = 0;
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    if (ch != '\n' && i < sentenceSize)
    {
      sentence[i] = ch;
      i++;
    }
    else
    {
     sentence[i] = '\0';
     i = 0;
     char field[20];
      getField(field, 0);
      accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  if (strcmp(field, "$GPRMC") == 0)
  {
    
    Serial.print("Tiempo: ");
    getField(field, 1);
    Serial.print(field);
    logfile.print(field);
    logfile.print("\t");   
    
    Serial.print("Lat: ");
    getField(field, 3);  // number
    Serial.print(field);
    logfile.print(field);
    logfile.print("\t");
    
    Serial.print("Long: ");
    getField(field, 5);  // number
    Serial.print(field);
    logfile.print(field);
    logfile.print("\t");

    Serial.print("Velocidad: ");
    getField(field, 7);
    Serial.print(field);
    logfile.print(field);
    
    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    logfile.print(ax);
    logfile.print("\t");
    Serial.print(ay); Serial.print("\t");
    logfile.print(ay);
    logfile.print("\t");
    Serial.print(az); Serial.print("\t");
    logfile.print(az);
    logfile.print("\t");
    Serial.print(gx); Serial.print("\t");
    logfile.print(gx);
    logfile.print("\t");
    Serial.print(gy); Serial.print("\t");
    logfile.print(gy);
    logfile.print("\t");
    Serial.println(gz);
    logfile.println(gz);
    logfile.flush();
    
  }
    }
  }
}

void getField(char* buffer, int index)
{
  int sentencePos = 0;
  int fieldPos = 0;
  int commaCount = 0;
  while (sentencePos < sentenceSize)
  {
    if (sentence[sentencePos] == ',')
    {
      commaCount ++;
      sentencePos ++;
    }
    if (commaCount == index)
    {
      buffer[fieldPos] = sentence[sentencePos];
      fieldPos ++;
    }
    sentencePos ++;
  }
  buffer[fieldPos] = '\0';
}

Now changing this value in the line // const int sentenceSize = 312; the sketch woks better or worse according that value, nontheless it always log in some point a line of data with strange characters.
Like this

115948.000 2400.0000 12100.0000 000.0-5948 2372 -15384 -266 70 -1
115948.200 24˜0.0000 12100.0000 000.0-6132 2260 -15532 -235 35 -4

The second line has a weir character there, it happens, according to the value, more or less often.
There is anyone who can help with this glitch?

Sounds as if you may be getting bit errors on the software serial connection. You may be able to reduce the frequency of the errors by playing with the serial parameters (you'd need to reconfigure the GPS to match, and I don't know what that would involve) or perhaps it could be affected by the properties of the circuit between the GPS and Arduino.

If you can't eliminate the errors, could you validate the received string to ensure it is syntactically correct before you store it? Evidently the string is only expected to contain decimal digits, a minus sign and whitespace so it should be easy enough to pick out the spurious characters.

I'd be inclined to reduce the baud rate on the GPS and the frequency with which it updates. Then see if you can get it working. Increasing the baud rate on the serial port may help too.