我正在编写交流程序,以产生一个正弦波,在给定时间间隔内缓慢地将频率从f1加速到f2.
我已经编写了这个c程序,将频率从0到10 Hz加速,但问题是360度完成后频率会发生变化.如果我尝试在0到360度之间改变频率,那么转换不平滑且突然.
这是我用过的罪的等式y =幅度*sin(频率*相位)
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;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我为什么x2打印零.我想因为浮点表示X1四舍五入,有没有办法保持进动.
long double x1, x2;
x1= 0.087912088; // Note: 360/4095 = 0.087912088
x2 = 360/4095;
printf("%Lf, %Lf \n",x1, x2);
Run Code Online (Sandbox Code Playgroud)
结果:
x1 =0.087912
x2= 0.000000
Run Code Online (Sandbox Code Playgroud) 在 Linux 中,如何创建具有给定文本或十六进制模式的大文件(如 DEADBEEFDEADBEEFDEADBEEF ....)
我知道 dd 可用于创建大文件,但它不会写入所需的文本或十六进制模式
dd if=/dev/urandom of=/tmp/bigfile bs=blocksize count=size
Run Code Online (Sandbox Code Playgroud)
或者
dd if=/dev/zero of=/tmp/bigfile bs=blocksize count=size
Run Code Online (Sandbox Code Playgroud)