Discrete Cosine Analysis

Kurt Bryan and SIMIODE

A Mathematica notebook to load in an audio signal (stored in an Excel workbook) and perform a discrete cosine analysis of the frequency content.

Load in and Plot Signal:  Stored in file "gong.xlsx", save it somewhere you can access it.

s = Import["Base/gong.xlsx"];
fs = s[[1]];
n = Length[fs];

Compute the duration "T" of the signal, and set the sampling rate (16000 Hz).

samprate = 16000
T =N[ n/samprate]

A plot of the data

pdat = Table[{(j-0.5)/samprate,fs[[j,1]]},{j,1,n}];
ListPlot[pdat,AxesLabel->{"Time (seconds)","Signal Intensity"},ImageSize->Scaled[0.8],Joined->True]

For time t = 1 to t = 1.01 seconds plot from k = 16000 to k = 16161, roughly

pdat = Table[{(j-0.5)/samprate,fs[[j,1]]},{j,16000,16161}];
ListPlot[pdat,AxesLabel->{"Time (seconds)","Signal Intensity"},ImageSize->Scaled[0.8],Joined->True]

Compute the DCT of the Signal Vector and Plot

Use the built-in FourierDCT command.

Ccoef = FourierDCT[fs];

Display the DCT versus frequency (C[k] is frequency (k-1)/(2*T)).

Cdat = Table[{(k-1)/(2*T),Abs[Ccoef[[k,1]]]},{k,1,n}];
ListPlot[Cdat,AxesLabel->{"Frequency (hz)","Coefficient Magnitude"},ImageSize->Scaled[0.8],Joined->True,PlotRange->Full]