Digital Signal Processing Reference
In-Depth Information
// Noise_gen.c Pseudo-random sequence generation
#include "DSK6713_AIC23.h" //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;//set sampling rate
#include "noise_gen.h"
//header file for noise sequence
short fb;
shift_reg sreg;
//shift reg structure
interrupt void c_int11() //interrupt service routine
{
short prnseq; //for pseudo-random sequence
if(sreg.bt.b0) //sequence{1,-1}based on bit b0
prnseq = -8000; //scaled negative noise level
else
prnseq = 8000; //scaled positive noise level
fb =(sreg.bt.b0)^(sreg.bt.b1); //XOR bits 0,1
fb ^=(sreg.bt.b11)^(sreg.bt.b13);//with bits 11,13 ->fb
sreg.regval<<=1; //shift register 1 bit to left
sreg.bt.b0 = fb; //close feedback path
output_sample(prnseq); //output scaled sequence
return;
//return from interrupt
}
void main()
{
sreg.regval = 0xFFFF; //set shift register
fb = 1; //initial feedback value
comm_intr(); //init DSK, codec, McBSP
while (1); //infinite loop
}
FIGURE 2.26. Pseudorandom noise sequence generation program ( noise_gen.c ).
Example 2.16: Pseudorandom Noise Sequence Generation ( noise_gen )
The program noise_gen.c , shown in Figure 2.26, generates a pseudorandom noise
sequence. It uses a software-based implementation of a maximal-length sequence
technique for generating a pseudorandom sequence. An initial 16-bit seed is
assigned to a register. Bits b0, b1, b11, and b13 are XORed, and the result is placed
in a feedback variable. The register with the initial seed value is then shifted 1 bit
to the left. The feedback variable is then assigned to bit b0 of the register. A scaled
minimum or maximum is assigned to prnseq , depending on whether the register's
bit b0 is 0 or 1. This scaled value corresponds to the noise-level amplitude. The
header file noise_gen.h (on the CD) defines the shift register bits.
Build and run this project as noise_gen . You can view the noise in the time
domain or hear it. Increase the noise-level amplitude for a scaled value of
±
16,000
(in lieu of
8000) and verify that the noise generated is louder. Connect the output
to a spectrum analyzer. Verify that the output spectrum is relatively flat until the
cutoff frequency of approximately 3800 Hz, which represents the bandwidth of the
antialiasing filter on the codec AIC23.
±
Search WWH ::




Custom Search