### Install FFTW.jl Package Source: https://juliamath.github.io/FFTW.jl/stable/index This code snippet demonstrates how to install the FFTW package using the Julia package manager (Pkg). It is intended to be run within the Julia REPL. ```julia using Pkg Pkg.add("FFTW") ``` -------------------------------- ### Plot 1D Signal Spectrum using FFTW and Plots Source: https://juliamath.github.io/FFTW.jl/stable/examples This example demonstrates how to compute and plot the frequency spectrum of a 1D real-valued signal using the FFTW.jl package. It also utilizes Plots.jl for visualization. The input is a time-domain signal, and the output is a plot showing both the time-domain signal and its frequency spectrum. Dependencies include FFTW.jl and Plots.jl. ```julia using Plots using FFTW # Number of points N = 2^12 - 1 # Sample spacing Ts = 1 / (1.1 * N) # Sample rate fs = 1 / Ts # Start time t0 = 0 tmax = t0 + N * Ts # time coordinate t = t0:Ts:tmax # The underlying signal here is the sum of a sine wave at 60 cycles per second # and its second harmonic (120 cycles per second) at half amplitude. We have # discrete observations (samples) of this signal at each time `t`, with `fs` # samples per second. signal = sin.(2π * 60 * t) + .5 * sin.(2π * 120 * t) # The `fft` function calculates the (discrete) Fourier transform of its input. # The first half of the returned array contains the positive frequencies, while # the second half contains the negative ones. For visualization purposes, we # rearrange the array to have the zero-frequency at the center. F = fftshift(fft(signal)) freqs = fftshift(fftfreq(length(t), fs)) # Plot time_domain = plot(t, signal, title="Signal", xlims=(0, 4 / 60), xlabel="time (s)", label="") freq_domain = plot(freqs, abs.(F), title="Spectrum", xlims=(0, 200), xlabel="frequency (Hz)", label="") plot(time_domain, freq_domain, layout = 2) savefig("Wave.pdf") ``` -------------------------------- ### FFTW.set_provider!: Set FFT Provider Source: https://juliamath.github.io/FFTW.jl/stable/fft A convenience function to set the FFT provider. Accepted provider values include strings like 'fftw' and 'mkl'. It also supports special sentinel values from the `Preferences` module (`nothing` and `missing`), which have specific meanings detailed in the `Preferences.set_preferences!()` docstring. ```Julia FFTW.set_provider!(provider; export_prefs::Bool = false) ``` -------------------------------- ### FFTW.plan_dct: Pre-plan Optimized Discrete Cosine Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Creates a pre-planned, optimized function for computing DCTs, similar to `plan_fft`. This function generates a plan that can be reused for multiple DCT calculations, improving performance. The initial arguments mirror those of `dct`. ```Julia FFTW.plan_dct(A [, dims [, flags [, timelimit [, num_threads]]]]) ``` -------------------------------- ### FFTW.plan_dct!: Pre-plan Optimized In-place Discrete Cosine Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Pre-plans an optimized function for in-place DCT computations, similar to `plan_fft`. This is useful for scenarios where repeated in-place DCTs are required, optimizing performance by pre-calculating transform steps. ```Julia FFTW.plan_dct!(A [, dims [, flags [, timelimit [, num_threads]]]]) ``` -------------------------------- ### FFTW.plan_r2r!: Pre-plan Optimized In-place Real-to-Real Fourier Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Pre-plans an optimized in-place r2r transform, analogous to `plan_fft`. This function generates an optimized plan for in-place r2r transformations, offering performance benefits when applied repeatedly to the same array structures. The arguments align with `r2r!`. ```Julia FFTW.plan_r2r!(A, kind [, dims [, flags [, timelimit [, num_threads]]]]) ``` -------------------------------- ### FFTW.plan_r2r: Pre-plan Optimized Real-to-Real Fourier Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Pre-plans an optimized r2r transform, similar to `plan_fft`. This function creates a plan that can be reused for multiple transforms of the same type and size, leading to significant performance improvements. The arguments correspond to those of `r2r` and `r2r!`. ```Julia FFTW.plan_r2r(A, kind [, dims [, flags [, timelimit [, num_threads]]]]) ``` -------------------------------- ### FFTW.plan_idct!: Pre-plan Optimized In-place Inverse Discrete Cosine Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Pre-plans an optimized function for in-place IDCT computations, comparable to `plan_fft`. This function is designed for scenarios demanding repeated in-place IDCT operations, offering performance enhancements through pre-computation. ```Julia FFTW.plan_idct!(A [, dims [, flags [, timelimit [, num_threads]]]]) ``` -------------------------------- ### FFTW.plan_idct: Pre-plan Optimized Inverse Discrete Cosine Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Generates a pre-planned, optimized function for computing IDCTs, analogous to `plan_fft`. This allows for efficient, repeatable IDCT computations. The first two arguments match those of `idct`. ```Julia FFTW.plan_idct(A [, dims [, flags [, timelimit [, num_threads]]]]) ``` -------------------------------- ### FFTW.r2r: Real-to-Real Fourier Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Performs multidimensional real-input/real-output (r2r) transforms of specified kinds. Supports various discrete cosine, sine, and Hartley transforms, as well as real-input DFT with half-complex output. The `kind` argument can specify transforms per dimension, and `dims` can limit the transform to specific dimensions. Consult the FFTW manual for detailed definitions. ```Julia FFTW.r2r(A, kind [, dims]) ``` -------------------------------- ### FFTW.r2r!: In-place Real-to-Real Fourier Transforms Source: https://juliamath.github.io/FFTW.jl/stable/fft Performs the same r2r transform as `FFTW.r2r` but operates in-place on the input array `A`. The array `A` must contain real or complex floating-point numbers. This function is suitable for memory-constrained operations where modifying the original array is acceptable. ```Julia FFTW.r2r!(A, kind [, dims]) ``` -------------------------------- ### FFTW.idct!: In-place Multidimensional Inverse Discrete Cosine Transform Source: https://juliamath.github.io/FFTW.jl/stable/fft Computes the IDCT in-place on array `A`. This function mirrors `idct` but performs the operation directly on the input array, making it suitable for memory-sensitive applications where the original array can be overwritten. ```Julia FFTW.idct!(A [, dims]) ``` -------------------------------- ### FFTW.idct: Multidimensional Inverse Discrete Cosine Transform Source: https://juliamath.github.io/FFTW.jl/stable/fft Computes the multidimensional inverse discrete cosine transform (IDCT), equivalent to a type-III DCT with unitary normalization. Similar to `dct`, the `dims` argument targets specific dimensions. Efficiency is enhanced when dimensions are products of small primes (see `nextprod`). `plan_idct` can provide greater performance for repeated computations. ```Julia FFTW.idct(A [, dims]) ``` -------------------------------- ### FFTW.dct: Multidimensional Discrete Cosine Transform Source: https://juliamath.github.io/FFTW.jl/stable/fft Computes a multidimensional type-II discrete cosine transform (DCT) of an array `A` using unitary normalization. The `dims` argument allows specifying the dimensions to transform. For optimal performance, array dimensions along the transformed axes should be products of small primes; refer to `nextprod` for guidance. Consider `plan_dct` for further efficiency gains. ```Julia FFTW.dct(A [, dims]) ``` -------------------------------- ### FFTW.dct!: In-place Multidimensional Discrete Cosine Transform Source: https://juliamath.github.io/FFTW.jl/stable/fft Performs the DCT in-place on array `A`. This function is identical to `dct` but modifies the input array directly, requiring `A` to be an array of real or complex floating-point values. This is beneficial for memory efficiency when the original data does not need to be preserved. ```Julia FFTW.dct!(A [, dims]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.