I have not tried the solution by JackDanIce, but I would guess it will only work if there is only one basic frequency.
If there is more than one overlapping
component wave making up the signal, the Excel Fast Fourier Transform (FFT) in the data analysis toolpack can be used, with some limitations as below.
The number of data points must be a power of 2.
In the example below, 512 (2 to the ninth) data points are used.
The example uses one
SumWave which is made up of 3
component waves.
In Row 26 is the relative amplitudes of the
component waves;
1,
2,
3.
In Row 27 is the relative frequencies of the
component waves;
1,
3,
5.
In Row 28 is the relative phase of the
component waves; 0, 90 and 180 degrees (this makes no difference to the result).
The formulas in A30 to H30 are copied down through Row 541
In Columns starting in Row 30 to Row 541:
A -- Degrees for SIN Function
B --
SumWave sum of
component wave functions:
C, D, E -- in columns C, D, E
F -- Time which is one unit, call it 1 minute corresponding to the 360 degrees or one radian
G -- FFTfreq (FREQUENCY)
H -- FFTamp (AMPLITUDE)
I -- FFTcomplex (resulting complex number) installed by sheet change macro code in Sheet1 code module (see code below)
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F | G | H | I |
---|
26 | 1 | amp | 1 | 2 | 3 | | | | |
---|
27 | 2 | freq | 1 | 3 | 5 | | | | |
---|
28 | 90 | SHIFT | 0 | 90 | 180 | | | | |
---|
29 | Degrees | SumWave | Wave1 | Wave2 | Wave3 | TIME | FFTfreq | FFTamp | FFTcomplex |
---|
30 | 0 | -2 | 0 | -2 | 1.84E-15 | 0 | 0 | 0 | 0 |
---|
|
---|
Excel 2003
Code:
Option Explicit
Dim ActyveCel As String, Addry As String, Addrz As String
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ERRO1
Addry = 30
Addrz = 541
Application.ScreenUpdating = False
ActyveCel = ActiveCell.Address
If AddIns("Analysis ToolPak").Installed = False Then AddIns("Analysis ToolPak").Installed = True
If AddIns("Analysis ToolPak - VBA").Installed = False Then AddIns("Analysis ToolPak - VBA").Installed = True
With Application
.EnableEvents = False
.EnableCancelKey = xlDisabled
.ScreenUpdating = False
.Calculation = xlManual
Range("I" & Addry & ":I" & Addrz).ClearContents
.Run "ATPVBAEN.XLA!Fourier", ActiveSheet.Range("$B$" & Addry & ":$B$" & Addrz), ActiveSheet.Range("$I$" & Addry & ":$I$" & Addrz), False, False
'This below is the inverse FFT
' .Run "ATPVBAEN.XLA!Fourier", ActiveSheet.Range("$I$" & Addry & ":$I$" & Addrz), ActiveSheet.Range("$J$" & Addry & ":$J$" & Addrz), True, False
End With
EX1T
Exit Sub
ERRO1:
EX1T
End Sub
Sub EX1T()
With Application
.Goto Range("A1")
.Goto Range(ActyveCel)
.Calculation = xlAutomatic
.ScreenUpdating = True
.EnableCancelKey = xlInterrupt
.EnableEvents = True
End With
On Error GoTo 0
End Sub
The 3
component waves in Columns C to E make up the
SumWave input wave in Column B for the FFTcomplex in Column I.
These 3 waves have amplitudes of
1,
2,
3.
These 3 waves have frequencies of
1,
3,
5.
Note that the resulting three peaks below corresponds to these amplitudes and frequencies.
Excel Workbook |
---|
|
---|
| G | H |
---|
29 | FFTfreq | FFTamp |
---|
30 | 0 | 0 |
---|
31 | 1 | 1 |
---|
32 | 2 | 0 |
---|
33 | 3 | 2 |
---|
34 | 4 | 0 |
---|
35 | 5 | 3 |
---|
36 | 6 | 0 |
---|
|
---|
Excel 2003
There can be a line chart for the amplitudes of the 3
component input waves and the
SumWave of these 3, on vertical axis, versus Degrees in Column A on the horizontal axis, in the range from Cell A1 to G25.
There can be a scatter chart for the FFTamp in Column H on the vertical axis, and the FFT Complex in Column I on the horizontal axis, in the range from Cell H1 to N25.
No more than half of the points for the scatter plot should be plotted, for FFTfreq from 0 for up to 255, as the other half of the plot will tend to mirror the first half.