Discrete Fourier Transform (DFT)

Visualization functions

Fix time variable for sampled signals

FixTime[signal_, sampleRate_] := Module[{time, data}, time = Table[i/sampleRate, {i, 1, Length[signal]}] ; data = {time, signal}//Transpose] ;

Plot discrete-time signal as sequence of amplitude lines (large end point)

DiscreteListPlot[signal_, color_:Black, opts___] := Module[{data, g1, g2}, If[ ... intSize[.015], Point[#]} & /@ data ; Show[Graphics[{color, g1, g2}], opts] ] ;

Plot discrete-time signal as sequence of amplitude lines (small end point)

DiscreteListPlot2[signal_, color_:Black, opts___] := Module[{data, g1, g2}, If ... intSize[.005], Point[#]} & /@ data ; Show[Graphics[{color, g1, g2}], opts] ] ;

Fourier rearrange

FourierRearrange[fft] rearranges the result of an FFT (Mathematica function Fourier[ ]), to a easier to visualize the spectrum represented by 'fft'. The length of the list 'fft' is assumed to be even; if it is not, the last term in 'fft' is dropped.

FourierRearrange[fft_, samplingRate_] := Module[{fft2, n, n2}, If[EvenQ[Length ... n2 + 1, n2}], Take[fft2, {n2 + 2, n2 * 2}] ~ Join ~ Take[fft2, {1, n2 + 1}]}//Transpose] ;

Filtering definitions

Filter[n, sampleRate, {lowFreq, highFreq}] generates an ideal discrete filter for an FFT list of length 'n' (sampled at 'sampleRate'), with a bandpass from 'lowFreq' to 'highFreq' (in Hz).

Filter[n_, samplingRate_, {lowF_, highF_}] := Module[{coeff, l, h}, coeff = Ta ... l + 1, h + 1}]] ; coeff = ReplacePart[coeff, 1, Table[{i}, {i, n + 1 - h, n + 1 - l}]] ] ;

Sampler (CT to DT converter)

Sampler[xc_, fs_, range_: {0, 5}] := Table[{n, xc[n/fs]}, {n, range[[1]] * fs, range[[2]] * fs}] ;

Discrete Fourier Transform

DFT[x_] := Module[{x2, k}, If[Length[First[x]] > 1, x2 = Last /@ x, x2 = x] ;  {Table[k, {k, 0, Length[x2] - 1}], Fourier[x2]} // Transpose] ;


Created by Mathematica  (February 16, 2004)