Navigation:  Programmer's Reference >

Computation: FFT and histograms

 

Previous pageReturn to chapter overviewNext page
Show/Hide Hidden Text

DPlot provides FFT and histogram functions which are very easy to use.

 

Here is a step-by-step example:

 

hmtoggle_plus1Open a wav file from Windows media directory

! open a wav file "tada.wav" from Windows media directory

Doc_num=FNDplot_doc_open(FNDplot_getsfpath$("CSIDL_WINDOWS","Media",0)&"\tada.wav")

Dummy=FNDplot_send_cmd("[Color(1,0,0,255)]") ! curve 1 = blue

 

hmtoggle_plus1Create FFT from wav data (Curve 1 = left channel)

Dummy=FNDplot_send_cmd("[SelectCurve(1)]")    ! select Curve 1 = left channel

Dummy=FNDplot_send_cmd("[FFT()]")             ! the FFT command creates a *new* document

 

hmtoggle_plus1Some tweaking

! get the document number of the newly created document as a reference

Doc_num2=VAL(FNDplot_request$("","LastNewDocNum"))

!

! activate this document for subsequent commands

Dummy=FNDplot_doc_activ(Doc_num2)

Dummy=FNDplot_send_cmd("[Color(1,255,0,0)]") ! FFT curve = red

 

hmtoggle_plus1Show  the FFT diagram on the HTBasic screen

! show the diagram, 100% screen size

CALL Dplot_show(Doc_num2)

 

.. which should give the following result*:

clip0050

 

hmtoggle_plus1Now create a histogram from the wav data

! activate the document containing the wav data for subsequent commands

Dummy=FNDplot_doc_activ(Doc_num)

Dummy=FNDplot_send_cmd("[SelectCurve(1)]")  ! select Curve 1 = left channel

! make histogram of this curve (a new document will be created)

Dummy=FNDplot_send_cmd("[Histogram(0.020)]")

 

hmtoggle_plus1Some tweaking

! get the document number of the newly created document as a reference

Doc_num3=VAL(FNDplot_request$("","LastNewDocNum"))

!

! activate this document for subsequent commands

Dummy=FNDplot_doc_activ(Doc_num3)

Dummy=FNDplot_send_cmd("[Color(1,0,255,0)]") ! histogram curve = green

Dummy=FNDplot_send_cmd("[BarChartStyle(0x00000808)]") ! shaded bars, percentage labels

Dummy=FNDplot_send_cmd("[FillStyle(1,1)]")

 

hmtoggle_plus1Show  the histogram on the HTBasic screen

! show the diagram, 100% screen size

CALL Dplot_show(Doc_num3)

 

.. which should give the following result*:

clip0051

 

hmtoggle_plus1Close the DPlot documents

Dummy=FNDplot_doc_close(Doc_num)     ! close the document 1

Dummy=FNDplot_doc_close(Doc_num2)     ! close the document 2

Dummy=FNDplot_doc_close(Doc_num3)     ! close the document 3

 

 

lampe

Hint: è Example program 6 demonstrates how to create FFT and histogram plots

(see SUB DPlot_wavfiles).

 

 

* On Windows Vista the results may differ from the results shown here since Vista uses 44.1 kHz wav files where earlier Windows versions uses 22 kHz wav files.