Kompresja częstotliwoci

Š Marek Szczerba, 2000

<< Miscellaneous`Audio`<< Graphics`Graphics`<< CCRMA`SCMTheory`<< CCRMA`Windows`;

SetDirectory["D:\Mathematica\data"];

src = ReadSoundfile["example.wav"];

wind = HammingW[Length[src]];

trg = src*wind;

Multi = 4;

Oversampling

\(\(ovr = Table[0, {x, Length[src]*Multi}]; 

    For[i = 2, i < Length[src], \(i++\), 
	
      smps = Table[
          trg[[i + j]], {j, \(-1\), 1}]; 
      
	poly = Fit[smps, {1, x, x\^2}, x]; 
	
      For[j = 0, j < Multi, \(j++\), 
		
        ovr[[i*Multi + j]] = 
          poly /. \ x -> \((1 + j/Multi)\)]; 
]; 
\)\)

ListPlot[trg];

ListPlot[ovr];

padfct = 1;

zeros = Table[0, {x, padfct*Length[ovr]}];

\(snd = ovr; 
AppendTo[snd, zeros]; snd = Flatten[snd]; \)

Length[ovr]

data = 
      Table[Table[
          If[x*y <= Length[snd], 
            snd[[x*y]], 0], {x, 
            Length[snd]}], {y, Multi, 1, -1}];

ListPlot[data[[4]], PlotJoined -> True, PlotRange -> All];

spectrum = 
      Table[Abs[Fourier[data[[k]]]], {k, 
          Multi}];

spectrum = 
      Table[Table[
          spectrum[[y, x]], {x, 
            Length[spectrum[[1]]]/2}], {
          y, Multi}];

\(aplot = 
      ListPlot[spectrum[[1]], 
        PlotRange -> All, Frame -> False, PlotJoined -> True, 
        PlotStyle -> RGBColor[0, 0, 1], Ticks -> None, 
        FrameTicks -> Automatic]; 

    bplot = ListPlot[spectrum[[2]], 
        PlotRange -> All, Frame -> False, PlotJoined -> True, 
        PlotStyle -> RGBColor[1, 0, 0], Ticks -> None, 
        FrameTicks -> Automatic]; 

    cplot = ListPlot[spectrum[[3]], 
        PlotRange -> All, Frame -> False, PlotJoined -> True, 
        PlotStyle -> RGBColor[0, 0.8, 0], Ticks -> None, 
        FrameTicks -> Automatic]; 
    dplot = ListPlot[spectrum[[4]], 
        PlotRange -> All, Frame -> False, PlotJoined -> True, 
        PlotStyle -> RGBColor[1, 0.8, 0.2], Ticks -> None, 
        FrameTicks -> Automatic]; \)

Show[{dplot, cplot, bplot, aplot}, Ticks -> None];

HarmSum = 
      (∑_(k = 1)^Multi) spectrum[[k
            ]]^2;

ListPlot[HarmSum, PlotRange -> {{0, 200}, All}, Frame -> False, 
      PlotJoined -> True, PlotStyle -> RGBColor[0, 0, 1], 
      Ticks -> {Automatic, None}, FrameTicks -> Automatic];

HarmLogProd = 
      Log[(∏_(k = 1)^Multi) spectrum[[k
              ]]^2];

ListPlot[HarmLogProd, PlotRange -> {{0, 200}, All}, Frame -> False, 
      PlotJoined -> True, PlotStyle -> RGBColor[0, 0, 1], 
      Ticks -> {Automatic, None}, FrameTicks -> Automatic];

HarmProd = 
      (∏_(k = 1)^Multi) spectrum[[k
            ]]^2;

ListPlot[HarmProd, PlotRange -> {{0, 200}, All}, Frame -> False, 
      PlotJoined -> True, PlotStyle -> RGBColor[0, 0, 1], 
      Ticks -> {Automatic, None}, FrameTicks -> Automatic];