📄 ics_helper.c
字号:
/*************************************************************************** ics_helper.c - Some useful functions ------------------- begin : 2003 authors : Linus Gasser emails : linus.gasser@epfl.ch***************************************************************************//*************************************************************************** Changes ------- date - name - description 03-12-01 - ineiti - create **************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#define DBG_LVL 4#include <math.h>#include "system.h"#include "debugging.h"#include "memory.h"#include "sdb.h"#include "ics_dev.h"#include "antenna.h"void init_dma_s16_buffer( s16 *buf, int length, int type ){ int count; for ( count=0; count<length; count++ ){ int f, x; switch( type ){ case 0: x = sin( count / 8. * M_PI ) * count * ( (double)0x7fff / length ); break; case 1: x = ( count % 16 > 4 ? 1 : -1 ) * 0x1000; break; case 2: x = ( count % 16 ) * 0x800; break; case 3: f = ( length - count ) * ( (double)0x7f / length ); x = sin( count / 8. ) * f; break; case 4: x = count % 2 ? 1 : -1; x *= 0x7fff; break; case 5: x = sin( ( count % 8 ) / 2. * M_PI ) * 0x7fff; break; case 6: x = ( 1. - (double)count / length ) * 0x7fff; break; case 7: x = (double)count / length * 0x7fff; break; case 8: x = 0x7fff; break; default: x = 0; } if ( count < 8 ){ PR_DBG( 0, "x[%i] = %4.4hx\n", count, x ); } // Oh well, the buf[count + ( count % 2 ? -1 : 1 ) ] = x; }}#define NR_TYPES 7void init_dma_s32_buffer( struct ics_dev *board, int data_index, int type ){ s32 *buf = board->params[data_index]->addr_tx; short bpf = board->blocks_per_frame; int count, count2, j; char type_str[NR_TYPES][32] = { "unity", "alternating triangle", "alternate", "unity triangle", "triangle with dirac", "random", "dirac" }; type = min( type, NR_TYPES - 1 ); type = max( type, 0 ); PR_DBG( 0, "Block-size: %i, bpf: %i, type: %i (%s)\n", board->block_size, bpf, type, type_str[ type ] ); for ( count2 = 0; count2 < bpf; count2++, buf += board->block_size ){ for ( count = 0; count<board->block_size; count++ ){ switch( type ){ case 0: buf[ count ] = 0x5fff5fff;// * ( 2 * (count % 2) - 1); break; case 1: if (count2 % 2){ j = ( board->block_size - count % board->block_size ) * 0x7ff / board->block_size; } else { j = ( count % board->block_size ) * 0x7ff / board->block_size; } buf[ count ] = 0x10001 * j; break; case 2: buf[ count ] = (count % 2 ? 0x7fff7fff : 0x80008000 ); break; case 3: buf[ count ] = ( 1 - (double)count / board->block_size ) * 0x7fff7fff; break; case 4: if ( count > 0 ){ buf[ count ] = ( 1. - (double)count / board->block_size ) * 0x3fff; if ( data_index % 2 ){ buf[ count ] = 0x3fff - buf[ count ]; } buf[ count ] *= 0x10001; } else { buf[ count ] = 0x7fff7fff; } break; case 5: // Well, some simple random-generator. Sure to be non-optimal. buf[ count ] = buf[ count - 1 ] * 0x93 + 0x1290328; break; case 6: // Impulse-generator buf[ count ] = (!count) * 0x6fff6fff; buf[ count ] += (!(count-4)) * 0x7fff7fff; break; } } } }void hanning( double *x, int len ){ int i; for ( i=0; i<len; i++ ){ x[i] *= .5 * ( 1. - cos( 2 * M_PI * i / ( len - 1 ) ) ); }}void dft (double *fr, double *fi, double *gr, double *gi, int n){ int i,j; double pi,x,q; pi = M_PI; x = 2*pi/n; for (i = 0; i < n; ++i){ gr[i] = 0; gi[i] = 0; for (j = 0; j < n; ++j){ q = x*j*( ( 3 * n / 2 - i ) % n ); gr[i] = gr[i]+fr[j]*cos(q)+fi[j]*sin(q); gi[i] = gi[i]+fi[j]*cos(q)-fr[j]*sin(q); } }}#define DFT_MAX 128// Show the FFT of data, where data is [re0][im0][re1][im1]...void show_dft( s32 *data, int dft_len, int hold ){ double re[dft_len], im[dft_len], fft_re[dft_len], fft_im[dft_len]; int count; static int a_max[DFT_MAX]; dft_len = min( dft_len, DFT_MAX ); // If we don't hold the fft, then we clear a_max if ( !hold ){ for ( count=0; count<dft_len; count++ ){ a_max[count] = 0; } } // Copy the data into doubles (for the hanning-window) for ( count=0; count<dft_len; count++ ){ re[count] = data[ count * 2 ] >> 8; im[count] = data[ count * 2 + 1 ] >> 8; } hanning( re, dft_len ); hanning( im, dft_len ); // Do the fft and show it dft( re, im, fft_re, fft_im, dft_len ); for( count = 0; count < dft_len; count++){ int a, re, im; re = fft_re[count]; im = fft_im[count]; a = hypot( re, im ); a_max[ count ] = max( a, a_max[ count ] ); PR_DBG(0,"F[%3i] = %10i, %10i = |%10i|\n", count - dft_len / 2, re, im, a_max[ count ] ); // Wait a bit so that the syslogger can do it's job rtl_udelay( 40 ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -