Last active
August 29, 2015 14:02
-
-
Save dzonesasaki/1819972d701aab4cc83b to your computer and use it in GitHub Desktop.
DFT on OpenOffice Calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub FourierTrans | |
Dim oSelFile As Object | |
Dim oSelSheet As Object | |
Dim uiLenStrm As Integer | |
Dim uiLenCoef As Integer | |
Dim uiLenOut As Integer | |
Dim fsumBuff As Double | |
oSelFile = ThisComponent | |
rem // get stream | |
rem // signalのシートのA列に信号,B1に信号の長さを入れておく.spectのシートを作っておく | |
oSelSheet = oSelFile.Sheets.getByName("signal") | |
uiLenStrm = oSelSheet.getCellByPosition(1, 0 ).Value | |
Dim mfStream( uiLenStrm+1) as Double | |
for uilp = 0 to uiLenStrm | |
mfStream(uilp) = oSelSheet.getCellByPosition(0, uilp ).Value | |
next uilp | |
rem // calculation Descrete Fourier Transform | |
Dim mfResultR( uiLenStrm+1) as Double | |
Dim mfResultI( uiLenStrm+1) as Double | |
for uilpA = 0 to uiLenStrm-1 | |
fsumBuffR = 0.0 | |
fsumBuffI = 0.0 | |
for uilpB = 0 to uiLenStrm-1 | |
fsumBuffR = fsumBuffR + mfStream(uilpB)*cos(2*PI*uilpA*uilpB/uiLenStrm) | |
fsumBuffI = fsumBuffI + mfStream(uilpB)*sin(2*PI*uilpA*uilpB/uiLenStrm) | |
next uilpB | |
mfResultR(uilpA)=fsumBuffR | |
mfResultI(uilpA)=fsumBuffI | |
next uilpA | |
oSelSheet = oSelFile.Sheets.getByName("spect") | |
for uilpA = 0 to uiLenStrm-1 | |
oSelSheet.getCellByPosition(0, uilpA ).Value = (uilpA)/uiLenStrm | |
oSelSheet.getCellByPosition(1, uilpA ).Value = mfResultR(uilpA) | |
oSelSheet.getCellByPosition(2, uilpA ).Value = mfResultI(uilpA) | |
oSelSheet.getCellByPosition(3, uilpA ).Value = mfResultR(uilpA)*mfResultR(uilpA)+mfResultI(uilpA)*mfResultI(uilpA) | |
rem oSelSheet.getCellByPosition(4, uilpA ).Value = atan(mfResultI(uilpA)/mfResultR(uilpA) + (mfResultI(uilpA)*mfResultR(uilpA))=0) | |
rem oSelSheet.getCellByPosition(4, uilpA ).Value = atan(mfResultI(uilpA)/mfResultR(uilpA) ) | |
next uilpA | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment