Skip to content

Commit

Permalink
Update playground
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-isaza committed Sep 10, 2016
1 parent 38aac9d commit 9f5c7e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
//: ## Fast Fourier Transform
//: This example shows how to perfrom a Fast Fourier Transform with Upsurge
import Upsurge
import XCPlayground
//: Let's define a function to plot all the values in a `ValueArray` to the timeline. If you don't see the timeline press ⌘⌥⏎
func plot(values: ValueArray<Double>, title: String) {
for value in values {
XCPlaygroundPage.currentPage.captureValue(value, withIdentifier: title)
}
}
import PlaygroundSupport
//: Start by generating uniformly-spaced x-coordinates
let count = 64
let frequency = 4.0
Expand All @@ -16,10 +10,13 @@ let x = ValueArray<Double>((0..<count).map({ step * Double($0) * frequency }))
//: And the sine-wave y-coordinates
let amplitude = 1.0
let y = amplitude * sin(x)
//: Now use the function we defined previously to plot the values
plot(y, title: "Sine Wave")
for value in y {
value
}
//: To compute the Fast Fourier Transform we initialize the `FFT` class with the number of samples
let fft = FFTDouble(inputLength: x.count)
//: Then compute power spectral density, which is the magnitudes of the FFT
let psd = fft.forwardMags(sin(x))
plot(psd, title: "FFT")
for value in psd {
value
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let arraySum = sum(array)
let a: ValueArray<Double> = [1.0, 3.0, 5.0, 7.0]
let b: ValueArray<Double> = [2.0, 4.0, 6.0, 8.0]
let c = a + b
//: You can also perform operation that are unique to `ValueArray`. This is how you would compute the dot product between two arrays
//: You can also perform operations that are unique to `ValueArray`. This is how you would compute the dot product between two arrays
let product = a b
//: You can also perform operations on parts of an array using the usual slice syntax
let d = a[0..<2] + b[2..<4]
Expand Down

0 comments on commit 9f5c7e1

Please sign in to comment.