Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0,1,0
- 0.1220703125,1,0
- 0.244140625,1,0
- 0.3662109375,1,0
- 0.48828125,1,0
- 0.6103515625,1,0
- .....
- -0.6103515625,1,0
- -0.48828125,1,0
- -0.3662109375,1,0
- -0.244140625,1,0
- -0.1220703125,1,0
- 0.000,819,0
- 0.001,805.600848087199,4.11892742135933E-12
- 0.002,766.191083986647,7.80009390410896E-12
- 0.003,703.07869137741,1.07704956064936E-11
- 0.004,619.930866652693,1.26768595620774E-11
- 0.005,521.519198753447,1.32877042702262E-11
- 0.006,413.390428478234,1.26576527037514E-11
- 0.007,301.48763797423,1.08400510789863E-11
- 8,0.008,191.750273447113,7.79765141345479E-12
- ....
- 8.186,413.390428478235,7.79385628257856E-09
- 8.187,521.519198753448,9.84392145575441E-09
- 8.188,619.930866652693,1.17116023545805E-08
- 8.189,703.07869137741,1.32913150485692E-08
- 8.19,766.191083986645,1.44921696865197E-08
- 8.191,805.600848087196,1.52439926792702E-08
- SF: Sample Frequency
- Samples: is array with samples 0..255
- N: is number of samples (8192)
- NP: is root of 2^NP = N (13)
- CF: cutoff freq of filter (30)
- W: number of coefficients in filter (40)
- dare: real data input
- daim: imaginary data input
- for i = 0 To N – 1
- {
- // time axis for graphing results
- time(i) = i / SF
- // freq axis for graphing, note symetric FFT so need -ve freq
- if i <= N / 2 then // Positive frequencies
- freq(i) = i * SF / N
- else // Negative frequencies
- freq(i) = i * SF / N - SF
- // copy input data to local array
- // and normalise to 127 = 0, centering the input/transform
- dare(i) = Samples(i) – 127
- daim(i) = 0
- }
- // fft the input data
- FFT(NP, N, dare, daim)
- // Create the impulse response of the filter in the frequency domain
- // this could be any filter but I use a simple box here: 1 in the passband and 0 elsewhere. Could use any filter here:
- // Note that I used symmetric complex FFT: it is necessary
- // fill in the negative frequencies as well.
- for i = 0 To N - 1
- {
- re(i) = 0
- if i <= (CF * N / SF) or i >= (N - CF * N / SF)
- re(i) = 1
- im(i) = 0
- }
- // Inverse filter into the time domain
- // Note: imaginary parts should be ~ 0 after iFFT
- IFFT(NP, N, re, im)
- // Hann window to truncate the filter series at say +/-20
- // can use other window formulas (e.g. bartlett) if desired
- for i = 0 To N – 1
- {
- window(i) = 0
- if i <= Won2 then
- window(i) = (0.5 + 0.5 * Cos(i * 2pi / (W + 1)))
- else if i >= N - Won2 then
- window(i) = (0.5 + 0.5 * Cos((N - i) * 2pi / (W + 1)))
- }
- // Apply the Hann window to the filter
- for i = 0 To N – 1
- {
- //careful here if complex multiply required
- re(i) = re(i) * window(i)
- im(i) = 0
- }
- // can IFFT and check for freq response and back again
- // Shift the filter to make it i.e. +ve times only
- //shift lower coefs up
- for i = Won2 To 0 Step -1
- {
- re(i + Won2) = re(i) //
- }
- //wrap -ve coeffs around
- for i = 0 To Won2 – 1
- {
- re(i) = re(N - Won2 + i) //wrap N -> 0, N - 1 -> 1 etc
- re(N - Won2 + i) = 0
- }
- // Transform filter back into the frequency domain
- FFT(NP, N, re, im)
- //multiply input data by filter COMPLEX MULT REQUIRED!!
- // may be able to shorten this step if desired
- for i = 0 To N – 1
- {
- tmpre = dare(i) * re(i) - daim(i) * im(i)
- tmpim = dare(i) * im(i) + daim(i) * re(i)
- dare(i) = tmpre
- daim(i) = tmpim
- }
- //inverse back to time domain
- IFFT(NP, N, dare, daim)
- // copy back to input normalised and re centered
- // may need to normalise/scale at this stage
- for i = 0 To N – 1
- {
- Samples(i) = dare(i) + 127
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement