Talk:Raised cosine

From Wikipedia, the free encyclopedia

why does the image use an alpha = 2 when the text clearly says alpha lives in [0,1]?


  • order: order of the filter
  • f_cut: cut frequency of the lowpass filter
  • Rolloff: rolloff factor [0..1]
  • Fs: sampling frequency

Matlab command

 firrcos( order, f_cut, Rolloff, Fs, 'rolloff' );

Matlab code equivalent

 % calculate taps
 for k=0:order / 2 
   temp_x( k + 1 ) = ( sinc( 2*k*Ts*f_cut ) * cos( 2*pi*Rolloff*k*Ts*f_cut ) ) / ( 1 - (2*Rolloff*k*Ts*f_cut)^2 );
 end;
 % mirror to Y 
 for k=1:order+1
   if( k <= order/2+1 ) 
     index = (order/2+1) - k + 1;
   else 
     index = k - order/2;
   end;
     X( k ) = temp_x( index );
 end;

C++ code

 static float sinc( float x )
 {
   if ( x == 0 ) 
     return 1.0;
   else
     return sin( PI*x ) / (PI*x);
 }
 static float pow( float x )
 {
   return x*x;
 } 
 static float* firrcos( int order, float f_cut, float Rolloff, int Fs )
 {
   float* temp_x = new float( order/2 +1 );
   float* X = new float( order + 1 );
   float  Ts = 1.0 / Fs;
   // taps      
   for (int k = 0; k <= order/2; k++) 
     temp_x[ k ] = sinc( 2*k*Ts*f_cut ) * cos( 2*PI*Rolloff*k*Ts*f_cut ) / pow( 1 - 2*Rolloff*k*Ts*f_cut );
   // mirror to Y axis
   for (int k = 0, index = 0; k < order+1; k++) 
   {
     if( k < order/2 + 1 )
       index = order/2 -k;
     else 
       index = k - order/2;
     X[ k ] = temp_x[ index ];          
   }
   return X;
 }