programs_1 - Programs from: "The Scientist and...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Programs from: "The Scientist and Engineer's Guide to Digital Signal Processing." Visit our website at: www.dspguide.com. All these programs may be copied, distributed, and used for any noncommercial purpose. TABLE 2-1 100 CALCULATION OF THE MEAN AND STANDARD DEVIATION 110 ' 120 DIM X[511] 'The signal is held in X[0] to X[511] 130 N% = 512 'N% is the number of points in the signal 140 ' 150 GOSUB XXXX 'Mythical subroutine that loads the signal into X[ ] 160 ' 170 MEAN = 0 'Find the mean via Eq. 2-1 180 FOR I% = 0 TO N%-1 190 MEAN = MEAN + X[I%] 200 NEXT I% 210 MEAN = MEAN/N% 220 ' 230 VARIANCE = 0 'Find the standard deviation via Eq. 2-2 240 FOR I% = 0 TO N%-1 250 VARIANCE = VARIANCE + ( X[I%] - MEAN )^2 260 NEXT I% 270 VARIANCE = VARIANCE/(N%-1) 280 SD = SQR(VARIANCE) 290 ' 300 PRINT MEAN SD 'Print the calculated mean and standard deviation 310 ' 320 END TABLE 2-2 100 'MEAN AND STANDARD DEVIATION USING RUNNING STATISTICS 110 ' 120 DIM X[511] 'The signal is held in X[0] to X[511] 130 ' 140 GOSUB XXXX 'Mythical subroutine that loads the signal into X[ ] 150 ' 160 N% = 0 'Zero the three running parameters 170 SUM = 0 180 SUMSQUARES = 0 190 ' 200 FOR I% = 0 TO 511 'Loop through each sample in the signal 210 ' 220 N% = N%+1 'Update the three parameters 230 SUM = SUM + X(I%) 240 SUMSQUARES = SUMSQUARES + X(I%)^2 250 ' 260 MEAN = SUM/N% 'Calculate mean and standard deviation via Eq. 2-3 270 VARIANCE = (SUMSQUARES - SUM^2/N%) / (N%-1) 280 SD = SQR(VARIANCE) 290 '
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 300 PRINT MEAN SD 'Print the running mean and standard deviation 310 ' 320 NEXT I% 330 ' 340 END TABLE 2-3 100 'CALCULATION OF THE HISTOGRAM, MEAN, AND STANDARD DEVIATION 110 ' 120 DIM X%[25000] 'X%[0] to X%[25000] holds the signal being processed 130 DIM H%[255] 'H%[0] to H%[255] holds the histogram 140 N% = 25001 'Set the number of points in the signal 150 ' 160 FOR I% = 0 TO 255 'Zero, so it can be used as an accumulator 170 H%[I%] = 0 180 NEXT I% 190 ' 200 GOSUB XXXX 'Mythical subroutine that loads the signal into X%[ ] 210 ' 220 FOR I% = 0 TO 25000 'Calculate the histogram for 25001 points 230 H%[ X%[I%] ] = H%[ X%[I%] ] + 1 240 NEXT I% 250 ' 260 MEAN = 0 'Calculate the mean via Eq. 2-6 270 FOR I% = 0 TO 255 280 MEAN = MEAN + I% * H%[I%] 290 NEXT I% 300 MEAN = MEAN / N% 310 ' 320 VARIANCE = 0 'Calculate the standard deviation via Eq. 2-7 330 FOR I% = 0 TO 255 340 VARIANCE = VARIANCE + H[I%] * (I%-MEAN)^2 350 NEXT I% 360 VARIANCE = VARIANCE / (N%-1) 370 SD = SQR(VARIANCE) 380 ' 390 PRINT MEAN SD 'Print the calculated mean and standard deviation. 400 ' 410 END TABLE 2-4 100 'CALCULATION OF BINNED HISTOGRAM 110 ' 120 DIM X[25000] 'X[0] to X[25000] holds the floating point signal, 130 ' 'with each sample being in the range: 0.0 to 10.0 140 DIM H%[999] 'H%[0] to H%[999] holds the binned histogram 150 ' 160 FOR I% = 0 TO 999 'Zero the binned histogram for use as an accumulator 170 H%[I%] = 0 180 NEXT I%
Background image of page 2
Sheet1 Page 3 190 ' 200 GOSUB XXXX 'Mythical subroutine that loads the signal into X%[ ]
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

programs_1 - Programs from: "The Scientist and...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online