LITIUM
Electrónica Programacion C++ C# Assembly 8051 AVR ARM7 ARM9
viernes, 6 de enero de 2012
FFT ARM9 S3C2440
http://www.youtube.com/watch?v=HemL3kkgkVk
#include "def.h"
#include "math.h"
#include "float.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "lcd.h"
#include <stdlib.h>
#include <math.h>
/* function prototypes FFT */
void fft(int N, double (*x)[2], double (*X)[2]);
void fft_rec(int N, int offset, int delta, double (*x)[2], double (*X)[2], double (*XX)[2]);
void ifft(int N, double (*x)[2], double (*X)[2]);
void FTT_PAINT (int nn);
void init_FFT (void);
#define TWO_PI (6.2831853071795864769252867665590057683943L)
#define NN 256
int N = NN ; /* number of points in FFT */
double (*x)[2]; /* pointer to time-domain samples */
double (*X)[2]; /* pointer to frequency-domain samples */
double dummy; /* scratch variable */
int iFFT = 0; /* generic index */
U32 X_antigou[256][2];
#define RGB(g,r,b) (unsigned int)( (r << 16) + (g << 8) + b )
void init_FFT (void)
{
x = malloc(2 * N * sizeof(double));
X = malloc(2 * N * sizeof(double));
Lcd_printf( 15 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"0" );
Lcd_printf( 80 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"1K" );
Lcd_printf( 148 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"2K" );
Lcd_printf( 216 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"3K" );
Lcd_printf( 284 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"4K" );
Lcd_printf( 352 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"5K" );
Lcd_printf( 420 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"6K" );
Lcd_printf( 488 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"7K" );
Lcd_printf( 556 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"8K" );
Lcd_printf( 624 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"9K" );
Lcd_printf( 692 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"10K" );
Lcd_printf( 760 , 30 ,RGB( 0xff,0xff,0xff),RGB( 0x00,0x00,0x00),0,"11K" );
}
void FTT_PAINT (int nn)
{
int m;
int mmm;
U32 X1;
fft(nn, x, X);
mmm=0;
for (m = 1; m <= (nn/2)-1 ; m++ )
{ X1 = sqrt( pow(X[m][0],2) + pow(X[m][1],2) );
if((X1) >= 415 )
{X1 = 415;}
mmm = mmm+6;
Glib_Line( 10+mmm , 476 , 10+mmm , 476-X_antigou[m][0] ,RGB(0X00,0X00,0X00));
Glib_Line( 10+mmm , 476 , 10+mmm , 476-X1 ,RGB(0XFA,0X4F,0X02));
Glib_Line( 10+mmm+1 , 476 , 10+mmm+1 , 476-X_antigou[m][0] ,RGB(0X00,0X00,0X00));
Glib_Line( 10+mmm+1 , 476 , 10+mmm+1 , 476-X1 ,RGB(0XFA,0X4F,0X02));
Glib_Line( 10+mmm+2 , 476 , 10+mmm+2 , 476-X_antigou[m][0] ,RGB(0X00,0X00,0X00));
Glib_Line( 10+mmm+2 , 476 , 10+mmm+2 , 476-X1 ,RGB(0XFA,0X4F,0X02));
Glib_Line( 10+mmm+3 , 476 , 10+mmm+3 , 476-X_antigou[m][0] ,RGB(0X00,0X00,0X00));
Glib_Line( 10+mmm+3 , 476 , 10+mmm+3 , 476-X1 ,RGB(0XFA,0X4F,0X02));
Glib_Line( 10+mmm+4 , 476 , 10+mmm+4 , 476-X_antigou[m][0] ,RGB(0X00,0X00,0X00));
Glib_Line( 10+mmm+4 , 476 , 10+mmm+4 , 476-X1 ,RGB(0XFA,0X4F,0X02));
Glib_Line( 10+mmm+5 , 476 , 10+mmm+5 , 476-X_antigou[m][0] ,RGB(0X00,0X00,0X00));
X_antigou[m][1] = X1;
}
for (m = 1; m <= (nn/2)-1 ; m++ )
{ X_antigou[m][0] = X_antigou[m][1]; }
}
/*----------------------------------------------------------------------------
fft.c - fast Fourier transform and its inverse (both recursively)
Copyright (C) 2004, Jerome R. Breitenbach. All rights reserved.
The author gives permission to anyone to freely copy, distribute, and use
this file, under the following conditions:
- No changes are made.
- No direct commercial advantage is obtained.
- No liability is attributed to the author for any damages incurred.
----------------------------------------------------------------------------*/
/* FFT */
void fft(int N, double (*x)[2], double (*X)[2])
{
double (*XX)[2] = malloc(2 * N * sizeof(double));
fft_rec(N, 0, 1 , x, X, XX);
free(XX);
}
/* FFT recursion */
void fft_rec(int N, int offset, int delta, double (*x)[2], double (*X)[2], double (*XX)[2])
{
int N2 = N/2; /* half the number of points in FFT */
int k; /* generic index */
double cs, sn; /* cosine and sine */
int k00, k01, k10, k11; /* indices for butterflies */
double tmp0, tmp1; /* temporary storage */
if(N != 2) /* Perform recursive step. */
{
fft_rec(N2, offset, 2*delta, x, XX, X);
fft_rec(N2, offset+delta, 2*delta, x, XX, X);
for(k=0; k<N2; k++)
{
k00 = offset + k*delta; k01 = k00 + N2*delta;
k10 = offset + 2*k*delta; k11 = k10 + delta;
cs = cos(TWO_PI*k/(double)N); sn = sin(TWO_PI*k/(double)N);
tmp0 = cs * XX[k11][0] + sn * XX[k11][1];
tmp1 = cs * XX[k11][1] - sn * XX[k11][0];
X[k01][0] = XX[k10][0] - tmp0;
X[k01][1] = XX[k10][1] - tmp1;
X[k00][0] = XX[k10][0] + tmp0;
X[k00][1] = XX[k10][1] + tmp1;
}
}
else
{
k00 = offset; k01 = k00 + delta;
X[k01][0] = x[k00][0] - x[k01][0];
X[k01][1] = x[k00][1] - x[k01][1];
X[k00][0] = x[k00][0] + x[k01][0];
X[k00][1] = x[k00][1] + x[k01][1];
}
}
/* IFFT */
void ifft(int N, double (*x)[2], double (*X)[2])
{
int N2 = N/2; /* half the number of points in IFFT */
int i; /* generic index */
double tmp0, tmp1; /* temporary storage */
/* Calculate IFFT via reciprocity property of DFT. */
fft(N, X, x);
x[0][0] = x[0][0]/N; x[0][1] = x[0][1]/N;
x[N2][0] = x[N2][0]/N; x[N2][1] = x[N2][1]/N;
for(i=1; i<N2; i++)
{
tmp0 = x[i][0]/N; tmp1 = x[i][1]/N;
x[i][0] = x[N-i][0]/N; x[i][1] = x[N-i][1]/N;
x[N-i][0] = tmp0; x[N-i][1] = tmp1;
}
}
martes, 6 de diciembre de 2011
MORSE c++
#include
// PROTO
void MorseTX(char *letra,uint32_t Velo);
void Morse_Encoder (char *morse, uint32_t Velo );
//
char Buffer_Tx [] = "VVV LU7FJ LU7FJ FF99QE TST";
*/ EJEMPLO
Morse_Encoder (Buffer_Tx,30);
*/
char A[] = {'.','-',0};
char B[] = {'-','.','.','.',0};
char C[] = {'-','.','-','.',0};
char D[] = {'-','.','.',0};
char E[] = {'.',0};
char F[] = {'.','.','-','.',0};
char G[] = {'-','.','.',0};
char H[] = {'.','.','.','.',0};
char I[] = {'.','.',0};
char J[] = {'.','-','-','-',0};
char K[] = {'-','.','-',0};
char L[] = {'.','-','.','.',0};
char M[] = {'-','-',0};
char N[] = {'-','.',0};
char O[] = {'-','-','-',0};
char P[] = {'.','-','-','.',0};
char Q[] = {'-','-','.','-',0};
char R[] = {'.','-','.',0};
char S[] = {'.','.','.',0};
char T[] = {'-',0};
char U[] = {'.','.','-',0};
char V[] = {'.','.','.','-',0};
char W[] = {'.','-','-',0};
char X[] = {'-','.','.','-',0};
char Y[] = {'-','.','-','-',0};
char Z[] = {'-','-','.','.',0};
char SPACE[] = {' ',0};
char n1 []= {'.','-','-','-','-',0};
char n2 []= {'.','.','-','-','-',0};
char n3 []= {'.','.','.','-','-',0};
char n4 []= {'.','.','.','.','-',0};
char n5 []= {'.','.','.','.','.',0};
char n6 []= {'-','.','.','.','.',0};
char n7 []= {'-','-','.','.','.',0};
char n8 []= {'-','-','-','.','.',0};
char n9 []= {'-','-','-','-','.',0};
char n0 []= {'-','-','-','-','-',0};
void MorseTX( char *letra, uint32_t Velo )
{
uint32_t vel ;
uint32_t RV = 50 - Velo;
do
{
char x = (*letra);
switch(x)
{
case '.':
PORTC |= (1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(2);}
PORTC &= ~(1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(2);}
break;
case '-':
PORTC |= (1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(6);}
PORTC &= ~(1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(2);}
break;
case ' ':
PORTC &= ~(1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(8);}
break;
}
} while(*++letra) ;
for (vel = 0; vel < RV; vel++){_delay_ms(4);}
}
void Morse_Encoder (char *morse, uint32_t vpm )
{
do
{
char x = (*morse);
switch(x)
{
case 'A':
MorseTX(A,vpm);
break;
case 'B':
MorseTX(B,vpm);
break;
case 'C':
MorseTX(C,vpm);
break;
case 'D':
MorseTX(D,vpm);
break;
case 'E':
MorseTX(E,vpm);
break;
case 'F':
MorseTX(F,vpm);
break;
case 'G':
MorseTX(G,vpm);
break;
case 'H':
MorseTX(H,vpm);
break;
case 'I':
MorseTX(I,vpm);
break;
case 'J':
MorseTX(J,vpm);
break;
case 'K':
MorseTX(K,vpm);
break;
case 'L':
MorseTX(L,vpm);
break;
case 'M':
MorseTX(M,vpm);
break;
case 'N':
MorseTX(N,vpm);
break;
case 'O':
MorseTX(O,vpm);
break;
case 'P':
MorseTX(P,vpm);
break;
case 'Q':
MorseTX(Q,vpm);
break;
case 'R':
MorseTX(R,vpm);
break;
case 'S':
MorseTX(S,vpm);
break;
case 'T':
MorseTX(T,vpm);
break;
case 'U':
MorseTX(U,vpm);
break;
case 'V':
MorseTX(V,vpm);
break;
case 'W':
MorseTX(W,vpm);
break;
case 'X':
MorseTX(X,vpm);
break;
case 'Y':
MorseTX(Y,vpm);
break;
case 'Z':
MorseTX(Z,vpm);
break;
case ' ':
MorseTX(SPACE,vpm);
break;
case '0':
MorseTX(n0,vpm);
break;
case '1':
MorseTX(n1,vpm);
break;
case '2':
MorseTX(n2,vpm);
break;
case '3':
MorseTX(n3,vpm);
break;
case '4':
MorseTX(n4,vpm);
break;
case '5':
MorseTX(n5,vpm);
break;
case '6':
MorseTX(n6,vpm);
break;
case '7':
MorseTX(n7,vpm);
break;
case '8':
MorseTX(n8,vpm);
break;
case '9':
MorseTX(n9,vpm);
break;
}
} while (*++morse);
}
// PROTO
void MorseTX(char *letra,uint32_t Velo);
void Morse_Encoder (char *morse, uint32_t Velo );
//
char Buffer_Tx [] = "VVV LU7FJ LU7FJ FF99QE TST";
*/ EJEMPLO
Morse_Encoder (Buffer_Tx,30);
*/
char A[] = {'.','-',0};
char B[] = {'-','.','.','.',0};
char C[] = {'-','.','-','.',0};
char D[] = {'-','.','.',0};
char E[] = {'.',0};
char F[] = {'.','.','-','.',0};
char G[] = {'-','.','.',0};
char H[] = {'.','.','.','.',0};
char I[] = {'.','.',0};
char J[] = {'.','-','-','-',0};
char K[] = {'-','.','-',0};
char L[] = {'.','-','.','.',0};
char M[] = {'-','-',0};
char N[] = {'-','.',0};
char O[] = {'-','-','-',0};
char P[] = {'.','-','-','.',0};
char Q[] = {'-','-','.','-',0};
char R[] = {'.','-','.',0};
char S[] = {'.','.','.',0};
char T[] = {'-',0};
char U[] = {'.','.','-',0};
char V[] = {'.','.','.','-',0};
char W[] = {'.','-','-',0};
char X[] = {'-','.','.','-',0};
char Y[] = {'-','.','-','-',0};
char Z[] = {'-','-','.','.',0};
char SPACE[] = {' ',0};
char n1 []= {'.','-','-','-','-',0};
char n2 []= {'.','.','-','-','-',0};
char n3 []= {'.','.','.','-','-',0};
char n4 []= {'.','.','.','.','-',0};
char n5 []= {'.','.','.','.','.',0};
char n6 []= {'-','.','.','.','.',0};
char n7 []= {'-','-','.','.','.',0};
char n8 []= {'-','-','-','.','.',0};
char n9 []= {'-','-','-','-','.',0};
char n0 []= {'-','-','-','-','-',0};
void MorseTX( char *letra, uint32_t Velo )
{
uint32_t vel ;
uint32_t RV = 50 - Velo;
do
{
char x = (*letra);
switch(x)
{
case '.':
PORTC |= (1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(2);}
PORTC &= ~(1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(2);}
break;
case '-':
PORTC |= (1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(6);}
PORTC &= ~(1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(2);}
break;
case ' ':
PORTC &= ~(1<<PORTC4);
for (vel = 0; vel < RV; vel++){_delay_ms(8);}
break;
}
} while(*++letra) ;
for (vel = 0; vel < RV; vel++){_delay_ms(4);}
}
void Morse_Encoder (char *morse, uint32_t vpm )
{
do
{
char x = (*morse);
switch(x)
{
case 'A':
MorseTX(A,vpm);
break;
case 'B':
MorseTX(B,vpm);
break;
case 'C':
MorseTX(C,vpm);
break;
case 'D':
MorseTX(D,vpm);
break;
case 'E':
MorseTX(E,vpm);
break;
case 'F':
MorseTX(F,vpm);
break;
case 'G':
MorseTX(G,vpm);
break;
case 'H':
MorseTX(H,vpm);
break;
case 'I':
MorseTX(I,vpm);
break;
case 'J':
MorseTX(J,vpm);
break;
case 'K':
MorseTX(K,vpm);
break;
case 'L':
MorseTX(L,vpm);
break;
case 'M':
MorseTX(M,vpm);
break;
case 'N':
MorseTX(N,vpm);
break;
case 'O':
MorseTX(O,vpm);
break;
case 'P':
MorseTX(P,vpm);
break;
case 'Q':
MorseTX(Q,vpm);
break;
case 'R':
MorseTX(R,vpm);
break;
case 'S':
MorseTX(S,vpm);
break;
case 'T':
MorseTX(T,vpm);
break;
case 'U':
MorseTX(U,vpm);
break;
case 'V':
MorseTX(V,vpm);
break;
case 'W':
MorseTX(W,vpm);
break;
case 'X':
MorseTX(X,vpm);
break;
case 'Y':
MorseTX(Y,vpm);
break;
case 'Z':
MorseTX(Z,vpm);
break;
case ' ':
MorseTX(SPACE,vpm);
break;
case '0':
MorseTX(n0,vpm);
break;
case '1':
MorseTX(n1,vpm);
break;
case '2':
MorseTX(n2,vpm);
break;
case '3':
MorseTX(n3,vpm);
break;
case '4':
MorseTX(n4,vpm);
break;
case '5':
MorseTX(n5,vpm);
break;
case '6':
MorseTX(n6,vpm);
break;
case '7':
MorseTX(n7,vpm);
break;
case '8':
MorseTX(n8,vpm);
break;
case '9':
MorseTX(n9,vpm);
break;
}
} while (*++morse);
}
martes, 28 de junio de 2011
RMC - NMEA has its own version of essential gps pvt (position, velocity, time)
RMC - NMEA has its own version of essential gps pvt (position, velocity, time) data. It is called RMC, The Recommended Minimum, which will look similar to:
real :
$GPRMC,184203.999,V,2340.2965,S,04632.7430,W,000.0,000.0,280611,,,N*7E
union G_RMC
{
struct {
char RMC [6];
char UTC[10]; // Fix taken at UTC 184203.999
char Status[1]; // Status A=active or V=Void.
char Latitude[9]; // Latitude 2340.2965
char N_S[1]; // N / S
char Longitude[11]; // Longitude 04632.7430 E - W
char W_E[1]; // W / E
char Speed_k [5]; // Speed over the ground in knots
char Track_angle[5]; // Track angle in degrees True
char DATE [6]; // 280611 Date - 26rd of 06 2011
char Magnetic_V[5]; // Magnetic Variation
char Magnetic_W[1]; // "W" si hay datos
char Magnetic_N[1]; /* N novalid data ,
A modo outonomo ,
D diferencial ,
E estimado deat zone ,
M entrada manual
S modo simulado */
char checksum[2]; // checksum 7E
};
struct
{
char GPS_GPRMCN[];
};
};
union G_RMC GPS_RMC;
$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A Where: RMC Recommended Minimum sentence C 123519 Fix taken at 12:35:19 UTC A Status A=active or V=Void. 4807.038,N Latitude 48 deg 07.038' N 01131.000,E Longitude 11 deg 31.000' E 022.4 Speed over the ground in knots 084.4 Track angle in degrees True 230394 Date - 23rd of March 1994 003.1,W Magnetic Variation *6A The checksum data, always begins with *Note that, as of the 2.3 release of NMEA, there is a new field in the RMC sentence at the end just prior to the checksum. For more information on this field see here.
real :
$GPRMC,184203.999,V,2340.2965,S,04632.7430,W,000.0,000.0,280611,,,N*7E
union G_RMC
{
struct {
char RMC [6];
char UTC[10]; // Fix taken at UTC 184203.999
char Status[1]; // Status A=active or V=Void.
char Latitude[9]; // Latitude 2340.2965
char N_S[1]; // N / S
char Longitude[11]; // Longitude 04632.7430 E - W
char W_E[1]; // W / E
char Speed_k [5]; // Speed over the ground in knots
char Track_angle[5]; // Track angle in degrees True
char DATE [6]; // 280611 Date - 26rd of 06 2011
char Magnetic_V[5]; // Magnetic Variation
char Magnetic_W[1]; // "W" si hay datos
char Magnetic_N[1]; /* N novalid data ,
A modo outonomo ,
D diferencial ,
E estimado deat zone ,
M entrada manual
S modo simulado */
char checksum[2]; // checksum 7E
};
struct
{
char GPS_GPRMCN[];
};
};
union G_RMC GPS_RMC;
VTG - Velocity made good.
VTG - Velocity made good. The gps receiver may use the LC prefix instead of GP if it is emulating Loran output.
$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48 where: VTG Track made good and ground speed 054.7,T True track made good (degrees) 034.4,M Magnetic track made good 005.5,N Ground speed, knots 010.2,K Ground speed, Kilometers per hour *48 ChecksumNote that, as of the 2.3 release of NMEA, there is a new field in the VTG sentence at the end just prior to the checksum. For more information on this field see here.
Suscribirse a:
Entradas (Atom)