的正弦波,缓慢提升向上频率从f1到f2对于给定的时间 [英] sine wave that slowly ramps up frequency from f1 to f2 for a given time

查看:149
本文介绍了的正弦波,缓慢提升向上频率从f1到f2对于给定的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个C程序产生正弦波的缓慢提升了频率从f1到f2的给予时间间隔。

我写了这个C程序坡道从0频率为10赫兹,但问题是,360度结束后的频率变化。如果我试图改变介于0和360度的频率,过渡不平滑,这是突然的。

这是方程式的罪,我已经使用Y =幅度*罪(频率*相)

  INT主(INT ARGC,字符* argv的[]){

双Y,频​​率,相位;
诠释计数; //为了方便绘制在MATLAB中,因此所有的波S的X轴$ P $垫。
  为(频率= 0;频率小于10;频率+ = 1){
      对于(相位= 0;相< 360;相++){//阶段是360度
      Y = 3 *罪((计数* 6.283185)+(频率*(相*(3.14159 / 180))));
    的printf(%F%F%F \ N,频率,相位,Y);
   }
  算上++;
  }
返回EXIT_SUCCESS;
}
 

  1. 如何平滑地改变频率给定的时间?
  2. 我应该寻找到傅立叶变换?
解决方案

如果你想角频率(W = 2 PI六)线性变化随着时间的推移,然后 DW / DT = A W = W0 +(WN-W0)* T / TN (其中 T 从0到 TN 是W 的推移,从 W0 WN )。相是的积分,所以相= W0 T +(WN-W0)* T ^ 2 /(2万亿)(如OLI说):

 无效扫描(双F_START,双f_end,双间隔,诠释n_steps){
    的for(int i = 0; I< n_steps ++我){
        双Δ= I​​ /(浮点)n_steps;
        双T =周期*增量;
        双相= 2 * PI * T *(F_START +(f_end  -  F_START)*增量/ 2);
        而(阶段> 2 * PI)阶段 -  = 2 * PI; //可选
        的printf(%F%F%F,T,相* 180 / PI,3 *罪(第一阶段));
    }
}
 

(其中间隔TN和增量为t / TN)。

这里的输出相当于蟒蛇code(1-10Hz超过5秒):

 从数学进口PI,罪

高清扫描(F_START,f_end,间隔,n_steps):
    因为我在范围内(n_steps):
        增量= I /浮点(n_steps)
        T =间隔*三角洲
        相= 2 * PI * T *(F_START +(f_end  -  F_START)*增量/ 2)
        印花T,相* 180 / PI,3 *罪(相)

扫描(1,10,5,1000)
 

PS顺便说一句,如果您正在收听的是这个(或看着它 - 任何涉及人类感知),我怀疑你不想要一个线性增加,但指数之一。但是这是<一href="http://stackoverflow.com/questions/19771328/sine-wave-that-logarithmically-changes-between-frequencies-f1-and-f2-at-given-ti/19777462#19777462">a不同的问题 ...

I'm writing a c program to generate a sinusoidal wave that slowly ramps up frequency from f1 to f2 for a giving time interval.

I have written this c program to ramp the frequency from 0 to 10 Hz but the problem is that the frequency changes after completion of 360 degrees. If I try to change the frequency between 0 and 360 degree that the transition is not smooth and it is abrupt.

This is the equation the sin that I have used y = Amplitude*sin(freq*phase)

int main(int argc, char *argv[]) {

double y, freq,phase;
int count; // for convenience of plotting in matlab so all the waves are spread on x axis.
  for (freq = 0; freq < 10; freq+=1) {
      for (phase = 0; phase < 360; phase++) { // phase is 360 degrees
      y = 3 * sin((count*6.283185)+(freq*(phase*(3.14159/180))));   
    printf("%f %f %f \n", freq, phase, y);
   }
  count++;
  }
return EXIT_SUCCESS;
}

  1. How do I change frequency smoothly for a given time period?
  2. should I be looking into Fourier transformations?

解决方案

if you want angular frequency (w=2 pi f) to vary linearly with time then dw/dt = a and w = w0 + (wn-w0)*t/tn (where t goes from 0 to tn, w goes from w0 to wn). phase is the integral of that, so phase = w0 t + (wn-w0)*t^2/(2tn) (as oli says):

void sweep(double f_start, double f_end, double interval, int n_steps) {
    for (int i = 0; i < n_steps; ++i) {
        double delta = i / (float)n_steps;
        double t = interval * delta;
        double phase = 2 * PI * t * (f_start + (f_end - f_start) * delta / 2);
        while (phase > 2 * PI) phase -= 2 * PI; // optional
        printf("%f %f %f", t, phase * 180 / PI, 3 * sin(phase));
    }
}

(where interval is tn and delta is t/tn).

here's the output for the equivalent python code (1-10Hz over 5 seconds):

from math import pi, sin

def sweep(f_start, f_end, interval, n_steps):
    for i in range(n_steps):
        delta = i / float(n_steps)
        t = interval * delta
        phase = 2 * pi * t * (f_start + (f_end - f_start) * delta / 2)
        print t, phase * 180 / pi, 3 * sin(phase)

sweep(1, 10, 5, 1000)

ps incidentally, if you're listening to this (or looking at it - anything that involves human perception) i suspect you don't want a linear increase, but an exponential one. but that's a different question...

这篇关于的正弦波,缓慢提升向上频率从f1到f2对于给定的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆