DSP Lab. Week 1 Drawing sinusoidal waves Doug Young Suh Media Lab. Rm401 suh@khu.ac.kr Last update : September 8, 2015
MediaLab , Kyunghee University Sinusoidal wave 2018-11-21 MediaLab , Kyunghee University
MediaLab , Kyunghee University C-program #include <stdio.h> #include <conio.h> #include <math.h> main() { FILE *data = fopen("data.txt","w"); for(int i=0;i<1000;i++) fprintf(data,"%4d %10.2f\n",i,100.0+20.*sin(2.*3.14/100*(float)i)+40.*sin(2.*3.14/300*(float)i)); fclose(data); data = fopen("data440.txt","w"); for(i=0;i<4000;i++) fprintf(data,"%4d %10.2f\n",i,sin(2.*3.14*440.0/400000.*(float)i)); } 2018-11-21 MediaLab , Kyunghee University
MediaLab , Kyunghee University C++ program #include <iostream> //이 코드에서는 fstream만 사용하므로 iostream은 생략해도 됩니다. #include <fstream> #include <iomanip> #include <math.h> //math.h대신 cmath 써도 됩니다. using namespace std; int main() { ofstream outFile; outFile.open("data.txt", ios::out|ios::trunc); // ios::trunc로 덮어쓰기 파일 설정. for (int i = 0; i < 1000; i++) { outFile << i << " " << 100.0 + 20.*sin(2.*3.14 / 100 * (float)i) + 40.*sin(2.*3.14 / 300 * (float)i) << endl; } outFile.close(); outFile.open("data440.txt", ios::out|ios::trunc); for (int i = 0; i < 1000; i++) { outFile << i << " " << sin(2.*3.14*440.0 / 400000.*(float)i) << endl; } outFile.close(); return 0; } 2018-11-21 MediaLab , Kyunghee University
MediaLab , Kyunghee University Assignments Send to suh@khu.ac.kr. 2018-11-21 MediaLab , Kyunghee University