show.cpp
来自「This a framework to test new ideas in tr」· C++ 代码 · 共 587 行 · 第 1/2 页
CPP
587 行
}}void Show::shapeSignal( double *x, double *y, double abs_x, double abs_y, double scaleX, double scaleY, int len ){ int i = (int)abs_x; // dummy assign to not having warnings switch ( showType ) { case show_complex: // Set the scaling setAxisOptions( yLeft, QwtAutoScale::Floating ); setAxisScale( yLeft, -scaleY, scaleY ); setAxisOptions( xBottom, QwtAutoScale::Floating ); setAxisScale( xBottom, -scaleX, scaleX ); break; case show_real: // Show only the real part of it for ( i = 0; i < len; i++ ) { y[ i ] = x[ i ]; x[ i ] = ( double ) i; } // Write it to the plot setAxisOptions( yLeft, QwtAutoScale::Floating ); setAxisScale( yLeft, -scaleX, scaleX ); setAxisAutoScale( xBottom ); break; case show_imag: // Show only the imag part of it for ( i = 0; i < len; i++ ) { x[ i ] = ( double ) i; } // Write it to the plot setAxisOptions( yLeft, QwtAutoScale::Floating ); setAxisScale( yLeft, -scaleY, scaleY ); setAxisAutoScale( xBottom ); break; case show_abs: // We have to take the absolute value of the signal... abs_y = 0; for ( i = 0; i < len; i++ ) { y[ i ] = hypot( x[i], y[i] ); x[ i ] = ( double ) i; abs_y = fmax( abs_y, y[ i ] ); } if ( abs_y > scaleY ) { scaleY = abs_y; } else { scaleY -= ( scaleY - abs_y ) * zoomIn; } // Write it to the plot setAxisOptions( yLeft, QwtAutoScale::Floating ); setAxisScale( yLeft, 0, scaleY ); setAxisAutoScale( xBottom ); break; case show_fft: setAxisOptions( xBottom, QwtAutoScale::Floating ); setAxisScale( xBottom, -.5, .5 ); setAxisAutoScale( yLeft ); setAxisAutoScale( xBottom ); // Take the lower radix-2 only int len_2; len_2 = (int)pow( 2, floor( logb( len ) ) ); // Hanning window for ( i=0; i<len_2; i++ ){ // For a direct fft of the ics-stuff x[i] = x[ ( i/4 ) * 8 + ( i%4 ) ]; y[i] = y[ ( i/4 ) * 8 + ( i%4 ) ]; // Hanning-window x[i] *= .5 * ( 1. - cos( 2 * M_PI * i / ( len - 1 ) ) ); y[i] *= .5 * ( 1. - cos( 2 * M_PI * i / ( len - 1 ) ) ); } fft( x, y, (unsigned int)logb( len_2 ), FFT ); // Backup the vectors int si; si = len_2 * sizeof( double ); double *xo, *yo; xo = (double*)malloc( si * sizeof( double ) ); yo = (double*)malloc( si * sizeof( double ) ); memcpy( xo, x, si ); memcpy( yo, y, si ); for ( i=0; i < len; i++ ){ y[(len/2+i) % len] = 10*log10( hypot( xo[ i * len_2 / len ], yo[ i * len_2 / len ] ) ); x[i] = (double)i*len_2/len - len_2/2.; } free( xo ); free( yo ); break; default: break; }}void Show::slotFreeze( bool dF ) { freeze = dF; if ( !freeze ){ delete( plotZoomer ); setCanvasBackground( lightGray ); } // cout<<"freeze state : "<<freeze<<"\n";}void Show::close() { updateTimer->stop();}void Show::styling( int style ) { // cout<<"**********************************8 style : "<< style<<endl; switch ( style ) { case 0: // Points setCurveStyle( signal, QwtCurve::NoCurve ); setCurveSymbol( signal, QwtSymbol( QwtSymbol::Cross, QBrush( red ), QPen( red ), QSize( 8, 8 ) ) ); isLine = 0; break; case 1: // Lines setCurveStyle( signal, QwtCurve::Lines ); setCurveSymbol( signal, QwtSymbol( QwtSymbol::Rect, QBrush( red ), QPen( red ), QSize( 1, 1 ) ) ); isLine = 1; break; default: cout << "wrong style : " << style << endl; }}/** * This shows a dialog and allows to print to a ps, thus * exporting it... */void Show::slotExportPs() { QPrinter * printOut = new QPrinter(); printOut->setOutputToFile ( true ); if ( printOut->setup( ) ) { print( *printOut ); }}/** * This exports to a matlab-file which is also compatible with * octave. It defines a function that is the same as the filename. */void Show::slotExportML() { QFileDialog * fd = new QFileDialog( parent ); QString fileName; enum showType_e s = showType; fd->setMode( QFileDialog::AnyFile ); if ( fd->exec() != QFileDialog::Accepted ){ return; } fileName = fd->selectedFile(); // cout<<"print in file : "<<fileName<<"\n"; QFile *outfile = new QFile( fileName ); if ( outfile->open( IO_WriteOnly ) ) { // cout<<"file open\n"; QTextStream stream( outfile ); double *x, *y; int len = block->getNumOfSamples(); if ( !dComplex ){ if ( showType != show_abs && showType != show_fft && showType != show_plot ){ s = show_imag; } } block->Data( &x, &y, len, s ); stream << "function ret = " << outfile->name().replace( QRegExp( ".*/" ), "" ). replace( QRegExp( "\\..*" ), "" ) << "();\n" << "ret = [ " << endl; switch ( s ) { case show_complex: for ( int i = 0;i < len;i++ ) { stream << x[i] << "+" << y[i] << "*i\n"; } break; case show_real: for ( int i = 0;i < len;i++ ) { stream << x[i] << "\n"; } break; case show_imag: for ( int i = 0;i < len;i++ ) { stream << y[i] << "\n"; } break; case show_abs: for ( int i = 0;i < len;i++ ) { if((i%8)<4){ // hypot( a, b ) = sqrt( a^2 + b^2 ) stream << hypot( x[i], y[i] ) << "\n"; } } break; case show_plot: for ( int i = 0;i < len;i++ ) { stream << x[i] << " " << y[i] << "\n"; } break; default: break; } stream << "];"; free( x ); free( y ); } else cout << "open file failed \n"; outfile->close();}/** * This exports to a binary-file */void Show::slotExportBin() { QFileDialog * fd = new QFileDialog( parent ); QString fileName; enum showType_e s = showType; fd->setMode( QFileDialog::AnyFile ); if ( fd->exec() != QFileDialog::Accepted ){ return; } fileName = fd->selectedFile(); // cout<<"print in file : "<<fileName<<"\n"; QFile *outfile = new QFile( fileName ); if ( outfile->open( IO_WriteOnly ) ) { // cout<<"file open\n"; QTextStream stream( outfile ); double *x, *y; int len = block->getNumOfSamples(); if ( !dComplex ){ if ( showType != show_abs && showType != show_fft && showType != show_plot ){ s = show_imag; } } block->Data( &x, &y, len, s ); stream << len << "\n"; switch ( s ) { case show_complex: for ( int i = 0;i < len;i++ ) { stream << x[i] << "\t" << y[i] << "\n"; } break; case show_real: for ( int i = 0;i < len;i++ ) { stream << x[i]<< "\n"; } break; case show_imag: for ( int i = 0;i < len;i++ ) { stream << y[i]<< "\n"; } break; case show_abs: for ( int i = 0;i < len;i++ ) { stream << hypot( x[i], y[i] )<< "\n"; } break; case show_plot: for ( int i = 0;i < len;i++ ) { stream << x[i] << " " << y[i]<< "\n"; } break; default: break; } free( x ); free( y ); } else cout << "open file failed \n"; outfile->close();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?