Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.55 KB | None | 0 0
  1. #pragma once
  2. #include <cmath>
  3. #define M_PI 3.14159265358979323846
  4.  
  5. namespace PTD2 {
  6.  
  7. using namespace System;
  8. using namespace System::ComponentModel;
  9. using namespace System::Collections;
  10. using namespace System::Windows::Forms;
  11. using namespace System::Data;
  12. using namespace System::Drawing;
  13.  
  14. /// <summary>
  15. /// Summary for MyForm
  16. /// </summary>
  17. public ref class MyForm : public System::Windows::Forms::Form
  18. {
  19. public:
  20. MyForm(void)
  21. {
  22. InitializeComponent();
  23. //
  24. //TODO: Add the constructor code here
  25. //
  26. }
  27.  
  28. protected:
  29. /// <summary>
  30. /// Clean up any resources being used.
  31. /// </summary>
  32. ~MyForm()
  33. {
  34. if (components)
  35. {
  36. delete components;
  37. }
  38. }
  39. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
  40. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart2;
  41. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart3;
  42. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart4;
  43. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart5;
  44. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart6;
  45. private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart7;
  46.  
  47. private:
  48. /// <summary>
  49. /// Required designer variable.
  50. /// </summary>
  51. System::ComponentModel::Container ^components;
  52.  
  53. #pragma region Windows Form Designer generated code
  54. /// <summary>
  55. /// Required method for Designer support - do not modify
  56. /// the contents of this method with the code editor.
  57. /// </summary>
  58. void InitializeComponent(void)
  59. {
  60. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  61. System::Windows::Forms::DataVisualization::Charting::Legend^ legend1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  62. System::Windows::Forms::DataVisualization::Charting::Series^ series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  63. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea2 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  64. System::Windows::Forms::DataVisualization::Charting::Legend^ legend2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  65. System::Windows::Forms::DataVisualization::Charting::Series^ series2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  66. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea3 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  67. System::Windows::Forms::DataVisualization::Charting::Legend^ legend3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  68. System::Windows::Forms::DataVisualization::Charting::Series^ series3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  69. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea4 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  70. System::Windows::Forms::DataVisualization::Charting::Legend^ legend4 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  71. System::Windows::Forms::DataVisualization::Charting::Series^ series4 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  72. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea5 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  73. System::Windows::Forms::DataVisualization::Charting::Legend^ legend5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  74. System::Windows::Forms::DataVisualization::Charting::Series^ series5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  75. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea6 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  76. System::Windows::Forms::DataVisualization::Charting::Legend^ legend6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  77. System::Windows::Forms::DataVisualization::Charting::Series^ series6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  78. System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea7 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
  79. System::Windows::Forms::DataVisualization::Charting::Legend^ legend7 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
  80. System::Windows::Forms::DataVisualization::Charting::Series^ series7 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
  81. this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  82. this->chart2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  83. this->chart3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  84. this->chart4 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  85. this->chart5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  86. this->chart6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  87. this->chart7 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
  88. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->BeginInit();
  89. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart2))->BeginInit();
  90. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart3))->BeginInit();
  91. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart4))->BeginInit();
  92. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart5))->BeginInit();
  93. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart6))->BeginInit();
  94. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart7))->BeginInit();
  95. this->SuspendLayout();
  96. //
  97. // chart1
  98. //
  99. chartArea1->Name = L"ChartArea1";
  100. this->chart1->ChartAreas->Add(chartArea1);
  101. legend1->Name = L"Legend1";
  102. this->chart1->Legends->Add(legend1);
  103. this->chart1->Location = System::Drawing::Point(12, 12);
  104. this->chart1->Name = L"chart1";
  105. series1->ChartArea = L"ChartArea1";
  106. series1->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  107. series1->Legend = L"Legend1";
  108. series1->Name = L"Zad. 1";
  109. this->chart1->Series->Add(series1);
  110. this->chart1->Size = System::Drawing::Size(564, 306);
  111. this->chart1->TabIndex = 0;
  112. this->chart1->Text = L"chart1";
  113. this->chart1->Click += gcnew System::EventHandler(this, &MyForm::chart1_Click);
  114. //
  115. // chart2
  116. //
  117. chartArea2->Name = L"ChartArea1";
  118. this->chart2->ChartAreas->Add(chartArea2);
  119. legend2->Name = L"Legend1";
  120. this->chart2->Legends->Add(legend2);
  121. this->chart2->Location = System::Drawing::Point(582, 12);
  122. this->chart2->Name = L"chart2";
  123. series2->ChartArea = L"ChartArea1";
  124. series2->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  125. series2->Legend = L"Legend1";
  126. series2->Name = L"Zad. 2.A";
  127. this->chart2->Series->Add(series2);
  128. this->chart2->Size = System::Drawing::Size(564, 306);
  129. this->chart2->TabIndex = 1;
  130. this->chart2->Text = L"chart2";
  131. //
  132. // chart3
  133. //
  134. chartArea3->Name = L"ChartArea1";
  135. this->chart3->ChartAreas->Add(chartArea3);
  136. legend3->Name = L"Legend1";
  137. this->chart3->Legends->Add(legend3);
  138. this->chart3->Location = System::Drawing::Point(582, 324);
  139. this->chart3->Name = L"chart3";
  140. series3->ChartArea = L"ChartArea1";
  141. series3->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  142. series3->Legend = L"Legend1";
  143. series3->Name = L"Zad. 2.B";
  144. this->chart3->Series->Add(series3);
  145. this->chart3->Size = System::Drawing::Size(564, 306);
  146. this->chart3->TabIndex = 2;
  147. this->chart3->Text = L"chart3";
  148. this->chart3->Click += gcnew System::EventHandler(this, &MyForm::chart3_Click);
  149. //
  150. // chart4
  151. //
  152. chartArea4->Name = L"ChartArea1";
  153. this->chart4->ChartAreas->Add(chartArea4);
  154. legend4->Name = L"Legend1";
  155. this->chart4->Legends->Add(legend4);
  156. this->chart4->Location = System::Drawing::Point(582, 636);
  157. this->chart4->Name = L"chart4";
  158. series4->ChartArea = L"ChartArea1";
  159. series4->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  160. series4->Legend = L"Legend1";
  161. series4->Name = L"Zad. 2.C";
  162. this->chart4->Series->Add(series4);
  163. this->chart4->Size = System::Drawing::Size(564, 306);
  164. this->chart4->TabIndex = 3;
  165. this->chart4->Text = L"chart4";
  166. this->chart4->Click += gcnew System::EventHandler(this, &MyForm::chart4_Click);
  167. //
  168. // chart5
  169. //
  170. chartArea5->Name = L"ChartArea1";
  171. this->chart5->ChartAreas->Add(chartArea5);
  172. legend5->Name = L"Legend1";
  173. this->chart5->Legends->Add(legend5);
  174. this->chart5->Location = System::Drawing::Point(1152, 12);
  175. this->chart5->Name = L"chart5";
  176. series5->ChartArea = L"ChartArea1";
  177. series5->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  178. series5->Legend = L"Legend1";
  179. series5->Name = L"Zad. 3.A";
  180. this->chart5->Series->Add(series5);
  181. this->chart5->Size = System::Drawing::Size(564, 306);
  182. this->chart5->TabIndex = 4;
  183. this->chart5->Text = L"chart5";
  184. this->chart5->Click += gcnew System::EventHandler(this, &MyForm::chart5_Click);
  185. //
  186. // chart6
  187. //
  188. chartArea6->Name = L"ChartArea1";
  189. this->chart6->ChartAreas->Add(chartArea6);
  190. legend6->Name = L"Legend1";
  191. this->chart6->Legends->Add(legend6);
  192. this->chart6->Location = System::Drawing::Point(1152, 324);
  193. this->chart6->Name = L"chart6";
  194. series6->ChartArea = L"ChartArea1";
  195. series6->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  196. series6->Legend = L"Legend1";
  197. series6->Name = L"Zad. 3.B";
  198. this->chart6->Series->Add(series6);
  199. this->chart6->Size = System::Drawing::Size(564, 306);
  200. this->chart6->TabIndex = 5;
  201. this->chart6->Text = L"chart6";
  202. this->chart6->Click += gcnew System::EventHandler(this, &MyForm::chart6_Click);
  203. //
  204. // chart7
  205. //
  206. chartArea7->Name = L"ChartArea1";
  207. this->chart7->ChartAreas->Add(chartArea7);
  208. legend7->Name = L"Legend1";
  209. this->chart7->Legends->Add(legend7);
  210. this->chart7->Location = System::Drawing::Point(1152, 636);
  211. this->chart7->Name = L"chart7";
  212. series7->ChartArea = L"ChartArea1";
  213. series7->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
  214. series7->Legend = L"Legend1";
  215. series7->Name = L"Zad. 3.C";
  216. this->chart7->Series->Add(series7);
  217. this->chart7->Size = System::Drawing::Size(564, 306);
  218. this->chart7->TabIndex = 6;
  219. this->chart7->Text = L"chart7";
  220. this->chart7->Click += gcnew System::EventHandler(this, &MyForm::chart7_Click);
  221. //
  222. // MyForm
  223. //
  224. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  225. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  226. this->ClientSize = System::Drawing::Size(1725, 948);
  227. this->Controls->Add(this->chart7);
  228. this->Controls->Add(this->chart6);
  229. this->Controls->Add(this->chart5);
  230. this->Controls->Add(this->chart4);
  231. this->Controls->Add(this->chart3);
  232. this->Controls->Add(this->chart2);
  233. this->Controls->Add(this->chart1);
  234. this->Name = L"MyForm";
  235. this->Text = L"MyForm";
  236. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->EndInit();
  237. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart2))->EndInit();
  238. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart3))->EndInit();
  239. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart4))->EndInit();
  240. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart5))->EndInit();
  241. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart6))->EndInit();
  242. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart7))->EndInit();
  243. this->ResumeLayout(false);
  244.  
  245. }
  246. #pragma endregion
  247. public: void Widmo(double fs, double x[], double fi, double N, int zadanie) {
  248. double *X = new double[N - 1];
  249. double *a = new double[N - 1];
  250. double *b = new double[N - 1];
  251. double *z = new double[floor((N / 2) - 1)];
  252. double *fiw = new double[floor((N / 2) - 1)];
  253.  
  254. for (int k = 0; k < N; k++) {
  255. a[k] = 0;
  256. b[k] = 0;
  257. for (int n = 0; n < N; n++) {
  258. fi = (-2 * M_PI * n * k) / N;
  259. a[k] += x[n] * cos(fi);
  260. b[k] += x[n] * sin(fi);
  261. }
  262. if (k < (N / 2)) {
  263. z[k] = sqrt((pow(a[k], 2)) + (pow(b[k], 2)));
  264. fiw[k] = k * fs / N;
  265. switch (zadanie) {
  266. case 1:
  267. this->chart1->Series["Zad. 1"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  268. break;
  269. case 2:
  270. this->chart2->Series["Zad. 2.A"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  271. break;
  272. case 3:
  273. this->chart3->Series["Zad. 2.B"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  274. break;
  275. case 4:
  276. this->chart4->Series["Zad. 2.C"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  277. break;
  278. case 5:
  279. this->chart5->Series["Zad. 3.A"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  280. break;
  281. case 6:
  282. this->chart6->Series["Zad. 3.B"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  283. break;
  284. case 7:
  285. this->chart7->Series["Zad. 3.C"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
  286. break;
  287. default:
  288. break;
  289. }
  290. }
  291. }
  292. return;
  293. }
  294. public: double* FunkcjaZ(double A, double N, double f, double fs, double fi) {
  295. double *z = new double[N];
  296. for (int i = 0; i <= N; i++) {
  297. if (i <= (N / 4)) {
  298. z[i] = i*(4 / N);
  299. }
  300. else if (i <= (N / 2)) {
  301. z[i] = (-i*(4 / N)) + (2 * A);
  302. }
  303. else {
  304. z[i] = A*sin((2 * M_PI * f * (i - N / 2) / fs) + fi);
  305. }
  306. }
  307. return z;
  308. }
  309. private: System::Void chart1_Click(System::Object^ sender, System::EventArgs^ e) {
  310. double A, f, fi, fs, Ts, N;
  311. int zadanie;
  312.  
  313. zadanie = 1;
  314.  
  315. A = 1;
  316. f = 180;
  317. fi = (3 / 4)*M_PI;
  318. fs = 1500;
  319. Ts = 0.5;
  320. N = floor(Ts*fs);
  321.  
  322. double *x = new double[N];
  323.  
  324. for (int i = 0; i <= N; i++) {
  325. x[i] = A * sin(((2 * M_PI * f * i) / fs) + fi);
  326. }
  327.  
  328. Widmo(fs, x, fi, N, zadanie);
  329. }
  330. private: System::Void chart2_Click(System::Object^ sender, System::EventArgs^ e) {
  331. double A, f1, f2, o1, o2, fs, Ts, f, fi, N;
  332. int zadanie;
  333.  
  334. zadanie = 2;
  335.  
  336. A = 1;
  337. fs = 2500;
  338. Ts = 1.5;
  339. N = floor(Ts*fs);
  340. f = 1 / Ts;
  341. fi = (3 / 4)*M_PI;
  342.  
  343. double *z = new double[N];
  344. z = FunkcjaZ(A, N, f, fs, fi);
  345.  
  346. //A. omega1 > omega2
  347. double *x = new double[N];
  348. f1 = 1000;
  349. f2 = 10;
  350. o1 = 2 * M_PI * f1;
  351. o2 = 2 * M_PI * f2;
  352.  
  353. for (int i = 0; i <= N; i++) {
  354. x[i] = z[i] * sin((o1*i) / (f1)) * cos((o2*i) / (f2));
  355. }
  356.  
  357. Widmo(fs, x, fi, N, zadanie);
  358. }
  359. private: System::Void chart3_Click(System::Object^ sender, System::EventArgs^ e) {
  360. double A, f1, f2, o1, o2, fs, Ts, f, fi, N;
  361. int zadanie;
  362.  
  363. zadanie = 3;
  364.  
  365. A = 1;
  366. fs = 2500;
  367. Ts = 1.5;
  368. N = floor(Ts*fs);
  369. f = 1 / Ts;
  370. fi = (3 / 4)*M_PI;
  371.  
  372. double *z = new double[N];
  373. z = FunkcjaZ(A, N, f, fs, fi);
  374.  
  375. //B. omega1 < omega2
  376. double *x = new double[N];
  377. f1 = 10;
  378. f2 = 1000;
  379. o1 = 2 * M_PI * f1;
  380. o2 = 2 * M_PI * f2;
  381.  
  382. for (int i = 0; i <= N; i++) {
  383. x[i] = z[i] * sin((o1*i) / (f1)) * cos((o2*i) / (f2));
  384. }
  385.  
  386. Widmo(fs, x, fi, N, zadanie);
  387. }
  388. private: System::Void chart4_Click(System::Object^ sender, System::EventArgs^ e) {
  389. double A, f1, o, o2, fs, Ts, f, fi, N;
  390. int zadanie;
  391.  
  392. zadanie = 4;
  393.  
  394. A = 1;
  395. fs = 2500;
  396. Ts = 1.5;
  397. N = floor(Ts*fs);
  398. f = 1 / Ts;
  399. fi = (3 / 4)*M_PI;
  400.  
  401. double *z = new double[N];
  402. z = FunkcjaZ(A, N, f, fs, fi);
  403.  
  404. //C. omega1 = omega2
  405. double *x = new double[N];
  406. f1 = 500;
  407. o = 2 * M_PI * f1;
  408.  
  409. for (int i = 0; i <= N; i++) {
  410. x[i] = z[i] * sin((o*i) / (f1)) * cos((o*i) / (f1));
  411. }
  412.  
  413. Widmo(fs, x, fi, N, zadanie);
  414. }
  415. private: System::Void chart5_Click(System::Object^ sender, System::EventArgs^ e) {
  416. double f, fi, fs, Ts, N;
  417. int k, zadanie;
  418. f = 1;
  419. fs = 2500;
  420. Ts = 1.5;
  421. N = floor(Ts*fs);
  422. k = 8;
  423.  
  424. zadanie = 5;
  425.  
  426. double *x = new double[N];
  427.  
  428. for (int i = 0; i <= N; i++) {
  429. x[i] = 0.0;
  430. for (double j = 1; j <= k; j++) {
  431. x[i] += 1 / (2 * j - 1) * sin((2 * j - 1) * 2 * M_PI * f * (i / fs));
  432. }
  433. }
  434.  
  435. Widmo(fs, x, fi, N, zadanie);
  436. }
  437. private: System::Void chart6_Click(System::Object^ sender, System::EventArgs^ e) {
  438. double f, fi, fs, Ts, N;
  439. int k, zadanie;
  440.  
  441. f = 1;
  442. fs = 2500;
  443. Ts = 1.5;
  444. N = floor(Ts*fs);
  445. k = 16;
  446.  
  447. zadanie = 6;
  448.  
  449. double *x = new double[N];
  450.  
  451. for (int i = 0; i <= N; i++) {
  452. x[i] = 0.0;
  453. for (double j = 1; j <= k; j++) {
  454. x[i] += 1 / (2 * j - 1) * sin((2 * j - 1) * 2 * M_PI * f * (i / fs));
  455. }
  456. }
  457.  
  458. Widmo(fs, x, fi, N, zadanie);
  459. }
  460. private: System::Void chart7_Click(System::Object^ sender, System::EventArgs^ e) {
  461. double f, fi, fs, Ts, N;
  462. int k, zadanie;
  463. f = 1;
  464. fs = 2500;
  465. Ts = 1.5;
  466. N = floor(Ts*fs);
  467. k = 32;
  468.  
  469. zadanie = 7;
  470.  
  471. double *x = new double[N];
  472.  
  473. for (int i = 0; i <= N; i++) {
  474. x[i] = 0.0;
  475. for (double j = 1; j <= k; j++) {
  476. x[i] += 1 / (2 * j - 1) * sin((2 * j - 1) * 2 * M_PI * f * (i / fs));
  477. }
  478. }
  479.  
  480. Widmo(fs, x, fi, N, zadanie);
  481. }
  482.  
  483. };
  484. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement