Imports BasicDSP Public Class dsp2ex2 ' constant size of FFT Private Const FFTSIZE As Integer = 1024 ' global signal Dim wv As New Signal Public Sub DisplayGraph(ByVal filename As String) ' accumulator for average spectrum Dim meansp As New Spectrum(FFTSIZE, wv.Rate) Dim mcount As Integer = 0 ' for each window For i As Integer = 1 To wv.Count - FFTSIZE Step FFTSIZE / 2 ' chop out section Dim cwv As ComplexWaveform = wv.Cut(i, FFTSIZE).Float.Complex ' calculate spectrum Dim s As Spectrum = DFT.ComplexFFT(Window.Hamming(cwv)) ' add magnitudes into accumulator For j As Integer = s.First To s.Last meansp(j) += s(j).Mag Next mcount += 1 Next ' compute mean For j As Integer = meansp.First To meansp.Last meansp(j) /= mcount Next ' plot Dim gr As New Graph(Me.CreateGraphics, zgc) gr.PlotDbSpectrum(1, meansp.Half, "Mean spectrum of " & filename) zgc.Refresh() End Sub Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then If (wv.LoadWaveFile(OpenFileDialog1.FileName)) Then DisplayGraph(OpenFileDialog1.FileName) End If End If End Sub End Class