WDFT (Warped Discrete Fourier Transform)

WDFT (Warped Discrete Fourier Transform)

WDFT (Warped Discrete Fourier Transform) by Go

Implementation of Go language:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main

import (
"fmt"
"math"
"math/cmplx"
)

// 定义扭曲函数,这里以幂函数为例
func distortionFunction(omega float64) float64 {
return math.Pow(omega, 1.5) // 可根据需要修改扭曲函数
}

// 离散傅里叶变换
func dft(signal []float64) []complex128 {
N := len(signal)
result := make([]complex128, N)

for k := 0; k < N; k++ {
var sum complex128
for n := 0; n < N; n++ {
omega := -2 * math.Pi * float64(k*n) / float64(N)
sum += complex(signal[n], 0) * cmplx.Exp(complex(0, omega))
}
result[k] = sum
}

return result
}

// 扭曲离散傅里叶变换
func wdft(signal []float64) []complex128 {
N := len(signal)
spectrum := dft(signal)

for k := 0; k < N; k++ {
omega := 2 * math.Pi * float64(k) / float64(N)
warpedOmega := distortionFunction(omega)
spectrum[k] *= cmplx.Exp(complex(0, warpedOmega))
}

return spectrum
}

// 反离散傅里叶变换
func idft(spectrum []complex128) []float64 {
N := len(spectrum)
result := make([]float64, N)

for n := 0; n < N; n++ {
var sum complex128
for k := 0; k < N; k++ {
omega := 2 * math.Pi * float64(k*n) / float64(N)
sum += spectrum[k] * cmplx.Exp(complex(0, omega))
}
result[n] = real(sum) / float64(N)
}

return result
}

func main() {
// 生成一个简单的示例信号
signal := make([]float64, 8)
for i := range signal {
signal[i] = float64(i)
}

// 进行WDFT变换
spectrum := wdft(signal)

// 对频域表示进行处理(这里省略具体处理步骤)

// 进行反离散傅里叶变换
outputSignal := idft(spectrum)

// 输出结果
fmt.Println("原始信号:", signal)
fmt.Println("经过WDFT变换后的信号:", outputSignal)
}
Implementation of Rust language:

Cargo.toml

1
2
[dependencies]
num = "0.4"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::f64::consts::PI;
use num::complex::Complex;

// 定义扭曲函数
fn distortion_function(omega: f64) -> f64 {
omega.powf(1.5) // 可根据需要修改扭曲函数
}

// 离散傅里叶变换
fn dft(signal: &[f64]) -> Vec<Complex<f64>> {
let n = signal.len();
let mut spectrum = vec![Complex::new(0.0, 0.0); n];

for k in 0..n {
let mut sum = Complex::new(0.0, 0.0);
for n in 0..n {
let omega = -2.0 * PI * k as f64 * n as f64 / n as f64;
sum += Complex::new(signal[n], 0.0) * Complex::from_polar(1.0, omega);
}
spectrum[k] = sum;
}

spectrum
}

// 扭曲离散傅里叶变换
fn wdft(signal: &[f64]) -> Vec<Complex<f64>> {
let n = signal.len();
let spectrum = dft(signal);

let warped_spectrum: Vec<Complex<f64>> = spectrum
.iter()
.enumerate()
.map(|(k, &value)| {
let omega = 2.0 * PI * k as f64 / n as f64;
let warped_omega = distortion_function(omega);
value * Complex::from_polar(1.0, warped_omega)
})
.collect();

warped_spectrum
}

// 反离散傅里叶变换
fn idft(spectrum: &[Complex<f64>]) -> Vec<f64> {
let n = spectrum.len();
let mut signal = vec![0.0; n];

for n in 0..n {
let mut sum = Complex::new(0.0, 0.0);
for k in 0..n {
let omega = 2.0 * PI * k as f64 * n as f64 / n as f64;
sum += spectrum[k] * Complex::from_polar(1.0, omega);
}
signal[n] = sum.re / n as f64;
}

signal
}

fn main() {
// 生成一个简单的示例信号
let signal: Vec<f64> = (0..8).map(|i| i as f64).collect();

// 进行WDFT变换
let spectrum = wdft(&signal);

// 对频域表示进行处理(这里省略具体处理步骤)

// 进行反离散傅里叶变换
let output_signal = idft(&spectrum);

// 输出结果
println!("原始信号:{:?}", signal);
println!("经过WDFT变换后的信号:{:?}", output_signal);
}

WDFT (Warped Discrete Fourier Transform)

https://www.defense.ink/e324f38b.html

Author

Jack Liu

Posted on

2024-02-17

Updated on

2024-02-17

Licensed under