Skip to content

Instantly share code, notes, and snippets.

@dzonesasaki
Last active August 29, 2015 14:02
Show Gist options
  • Save dzonesasaki/32e5496b2f0f70f03887 to your computer and use it in GitHub Desktop.
Save dzonesasaki/32e5496b2f0f70f03887 to your computer and use it in GitHub Desktop.
FIR on OpenOffice_calc
Sub CalcFir
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に信号の長さを入れておく.
rem //coefのシートのA列に係数,B1に信号の長さを入れておく.
rem //resultシートを作っておく
oSelSheet = oSelFile.Sheets.getByName("signal")
uiLenStrm = oSelSheet.getCellByPosition(1, 0 ).Value
Dim miStream(uiLenStrm+1) as integer
for uilp = 0 to uiLenStrm
miStream(uilp) = oSelSheet.getCellByPosition(0, uilp ).Value
next uilp
rem // get coef
oSelSheet = oSelFile.Sheets.getByName("coef")
uiLenCoef = oSelSheet.getCellByPosition(1, 0 ).Value
Dim miCoef(uiLenCoef+1) as integer
for uilp = 0 to uiLenCoef
miCoef(uilp) = oSelSheet.getCellByPosition(0, uilp ).Value
next uilp
rem // calculation FIR
uiLenOut = uiLenStrm - uiLenCoef
Dim miResult( uiLenStrm+1) as Double
for uilpA = 0 to uiLenOut-1
fsumBuff = 0
for uilpB = 0 to uiLenCoef-1
fsumBuff = fsumBuff + miStream(uilpA + uilpB)*miCoef(uilpB)
next uilpB
miResult(uilpA+ uiLenCoef-1)=fsumBuff
next uilpA
rem // output result
oSelSheet = oSelFile.Sheets.getByName("result")
for uilpA = 0 to uiLenStrm-1
oSelSheet.getCellByPosition(0, uilpA ).Value = miResult(uilpA)
next uilpA
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment