我正在使用滑动窗口通过FFT从我的EEG数据中提取信息。现在,我要预测从我的窗口进入下一个窗口的信号。因此,我从0.25秒的时间窗中提取相位,以预测下一个0.25秒的长窗。
我是信号处理/预测的新手,所以我的知识有点生锈。
我无法使用提取的相位和频率生成正弦波。我只是找不到解决方案。谁知道,我可能只需要朝着正确的方向前进。
R中是否有功能可以帮助我生成合适的正弦波?
所以我在提取相位后有最大频率,需要用此信息生成一个波。
答案 0 :(得分:0)
这里是伪代码,用于合成选定频率的正弦曲线...当前它假定初始种子相移为零,因此如果需要不同的初始相移,只需更改theta值即可
func pop_audio_buffer(number_of_samples float64, given_freq float64,
samples_per_second float64) ([]float64, error) {
// output sinusoidal curve is assured to both start and stop at the zero cross over threshold,
// independent of supplied input parms which control samples per cycle and buffer size.
// This avoids that "pop" which otherwise happens when rendering audio curves
// which begins at say 0.5 of a possible range -1 to 0 to +1
int_number_of_samples := int(number_of_samples)
if int_number_of_samples == 0 {
panic("ERROR - seeing 0 number_of_samples in pop_audio_buffer ... float number_of_samples " +
FloatToString(number_of_samples) + " is your desired_num_seconds too small ? " +
" or maybe too low value of sample rate")
}
source_buffer := make([]float64, int_number_of_samples)
incr_theta := (2.0 * math.Pi * given_freq) / samples_per_second
theta := 0.0
for curr_sample := 0; curr_sample < int_number_of_samples; curr_sample++ {
source_buffer[curr_sample] = math.Sin(theta)
theta += incr_theta
}
return source_buffer, nil
} // pop_audio_buffer