Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <cmath>
- #define M_PI 3.14159265358979323846
- namespace PTD2 {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Summary for MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart2;
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart3;
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart4;
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart5;
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart6;
- private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart7;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea2 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea3 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea4 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend4 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series4 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea5 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea6 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea7 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
- System::Windows::Forms::DataVisualization::Charting::Legend^ legend7 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
- System::Windows::Forms::DataVisualization::Charting::Series^ series7 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
- this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- this->chart2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- this->chart3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- this->chart4 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- this->chart5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- this->chart6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- this->chart7 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart2))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart3))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart4))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart5))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart6))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart7))->BeginInit();
- this->SuspendLayout();
- //
- // chart1
- //
- chartArea1->Name = L"ChartArea1";
- this->chart1->ChartAreas->Add(chartArea1);
- legend1->Name = L"Legend1";
- this->chart1->Legends->Add(legend1);
- this->chart1->Location = System::Drawing::Point(12, 12);
- this->chart1->Name = L"chart1";
- series1->ChartArea = L"ChartArea1";
- series1->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series1->Legend = L"Legend1";
- series1->Name = L"Zad. 1";
- this->chart1->Series->Add(series1);
- this->chart1->Size = System::Drawing::Size(564, 306);
- this->chart1->TabIndex = 0;
- this->chart1->Text = L"chart1";
- this->chart1->Click += gcnew System::EventHandler(this, &MyForm::chart1_Click);
- //
- // chart2
- //
- chartArea2->Name = L"ChartArea1";
- this->chart2->ChartAreas->Add(chartArea2);
- legend2->Name = L"Legend1";
- this->chart2->Legends->Add(legend2);
- this->chart2->Location = System::Drawing::Point(582, 12);
- this->chart2->Name = L"chart2";
- series2->ChartArea = L"ChartArea1";
- series2->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series2->Legend = L"Legend1";
- series2->Name = L"Zad. 2.A";
- this->chart2->Series->Add(series2);
- this->chart2->Size = System::Drawing::Size(564, 306);
- this->chart2->TabIndex = 1;
- this->chart2->Text = L"chart2";
- //
- // chart3
- //
- chartArea3->Name = L"ChartArea1";
- this->chart3->ChartAreas->Add(chartArea3);
- legend3->Name = L"Legend1";
- this->chart3->Legends->Add(legend3);
- this->chart3->Location = System::Drawing::Point(582, 324);
- this->chart3->Name = L"chart3";
- series3->ChartArea = L"ChartArea1";
- series3->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series3->Legend = L"Legend1";
- series3->Name = L"Zad. 2.B";
- this->chart3->Series->Add(series3);
- this->chart3->Size = System::Drawing::Size(564, 306);
- this->chart3->TabIndex = 2;
- this->chart3->Text = L"chart3";
- this->chart3->Click += gcnew System::EventHandler(this, &MyForm::chart3_Click);
- //
- // chart4
- //
- chartArea4->Name = L"ChartArea1";
- this->chart4->ChartAreas->Add(chartArea4);
- legend4->Name = L"Legend1";
- this->chart4->Legends->Add(legend4);
- this->chart4->Location = System::Drawing::Point(582, 636);
- this->chart4->Name = L"chart4";
- series4->ChartArea = L"ChartArea1";
- series4->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series4->Legend = L"Legend1";
- series4->Name = L"Zad. 2.C";
- this->chart4->Series->Add(series4);
- this->chart4->Size = System::Drawing::Size(564, 306);
- this->chart4->TabIndex = 3;
- this->chart4->Text = L"chart4";
- this->chart4->Click += gcnew System::EventHandler(this, &MyForm::chart4_Click);
- //
- // chart5
- //
- chartArea5->Name = L"ChartArea1";
- this->chart5->ChartAreas->Add(chartArea5);
- legend5->Name = L"Legend1";
- this->chart5->Legends->Add(legend5);
- this->chart5->Location = System::Drawing::Point(1152, 12);
- this->chart5->Name = L"chart5";
- series5->ChartArea = L"ChartArea1";
- series5->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series5->Legend = L"Legend1";
- series5->Name = L"Zad. 3.A";
- this->chart5->Series->Add(series5);
- this->chart5->Size = System::Drawing::Size(564, 306);
- this->chart5->TabIndex = 4;
- this->chart5->Text = L"chart5";
- this->chart5->Click += gcnew System::EventHandler(this, &MyForm::chart5_Click);
- //
- // chart6
- //
- chartArea6->Name = L"ChartArea1";
- this->chart6->ChartAreas->Add(chartArea6);
- legend6->Name = L"Legend1";
- this->chart6->Legends->Add(legend6);
- this->chart6->Location = System::Drawing::Point(1152, 324);
- this->chart6->Name = L"chart6";
- series6->ChartArea = L"ChartArea1";
- series6->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series6->Legend = L"Legend1";
- series6->Name = L"Zad. 3.B";
- this->chart6->Series->Add(series6);
- this->chart6->Size = System::Drawing::Size(564, 306);
- this->chart6->TabIndex = 5;
- this->chart6->Text = L"chart6";
- this->chart6->Click += gcnew System::EventHandler(this, &MyForm::chart6_Click);
- //
- // chart7
- //
- chartArea7->Name = L"ChartArea1";
- this->chart7->ChartAreas->Add(chartArea7);
- legend7->Name = L"Legend1";
- this->chart7->Legends->Add(legend7);
- this->chart7->Location = System::Drawing::Point(1152, 636);
- this->chart7->Name = L"chart7";
- series7->ChartArea = L"ChartArea1";
- series7->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
- series7->Legend = L"Legend1";
- series7->Name = L"Zad. 3.C";
- this->chart7->Series->Add(series7);
- this->chart7->Size = System::Drawing::Size(564, 306);
- this->chart7->TabIndex = 6;
- this->chart7->Text = L"chart7";
- this->chart7->Click += gcnew System::EventHandler(this, &MyForm::chart7_Click);
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(1725, 948);
- this->Controls->Add(this->chart7);
- this->Controls->Add(this->chart6);
- this->Controls->Add(this->chart5);
- this->Controls->Add(this->chart4);
- this->Controls->Add(this->chart3);
- this->Controls->Add(this->chart2);
- this->Controls->Add(this->chart1);
- this->Name = L"MyForm";
- this->Text = L"MyForm";
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart2))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart3))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart4))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart5))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart6))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart7))->EndInit();
- this->ResumeLayout(false);
- }
- #pragma endregion
- public: void Widmo(double fs, double x[], double fi, double N, int zadanie) {
- double *X = new double[N - 1];
- double *a = new double[N - 1];
- double *b = new double[N - 1];
- double *z = new double[floor((N / 2) - 1)];
- double *fiw = new double[floor((N / 2) - 1)];
- for (int k = 0; k < N; k++) {
- a[k] = 0;
- b[k] = 0;
- for (int n = 0; n < N; n++) {
- fi = (-2 * M_PI * n * k) / N;
- a[k] += x[n] * cos(fi);
- b[k] += x[n] * sin(fi);
- }
- if (k < (N / 2)) {
- z[k] = sqrt((pow(a[k], 2)) + (pow(b[k], 2)));
- fiw[k] = k * fs / N;
- switch (zadanie) {
- case 1:
- this->chart1->Series["Zad. 1"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- case 2:
- this->chart2->Series["Zad. 2.A"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- case 3:
- this->chart3->Series["Zad. 2.B"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- case 4:
- this->chart4->Series["Zad. 2.C"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- case 5:
- this->chart5->Series["Zad. 3.A"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- case 6:
- this->chart6->Series["Zad. 3.B"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- case 7:
- this->chart7->Series["Zad. 3.C"]->Points->AddXY(static_cast<double>(fiw[k] / fs), z[k]);
- break;
- default:
- break;
- }
- }
- }
- return;
- }
- public: double* FunkcjaZ(double A, double N, double f, double fs, double fi) {
- double *z = new double[N];
- for (int i = 0; i <= N; i++) {
- if (i <= (N / 4)) {
- z[i] = i*(4 / N);
- }
- else if (i <= (N / 2)) {
- z[i] = (-i*(4 / N)) + (2 * A);
- }
- else {
- z[i] = A*sin((2 * M_PI * f * (i - N / 2) / fs) + fi);
- }
- }
- return z;
- }
- private: System::Void chart1_Click(System::Object^ sender, System::EventArgs^ e) {
- double A, f, fi, fs, Ts, N;
- int zadanie;
- zadanie = 1;
- A = 1;
- f = 180;
- fi = (3 / 4)*M_PI;
- fs = 1500;
- Ts = 0.5;
- N = floor(Ts*fs);
- double *x = new double[N];
- for (int i = 0; i <= N; i++) {
- x[i] = A * sin(((2 * M_PI * f * i) / fs) + fi);
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- private: System::Void chart2_Click(System::Object^ sender, System::EventArgs^ e) {
- double A, f1, f2, o1, o2, fs, Ts, f, fi, N;
- int zadanie;
- zadanie = 2;
- A = 1;
- fs = 2500;
- Ts = 1.5;
- N = floor(Ts*fs);
- f = 1 / Ts;
- fi = (3 / 4)*M_PI;
- double *z = new double[N];
- z = FunkcjaZ(A, N, f, fs, fi);
- //A. omega1 > omega2
- double *x = new double[N];
- f1 = 1000;
- f2 = 10;
- o1 = 2 * M_PI * f1;
- o2 = 2 * M_PI * f2;
- for (int i = 0; i <= N; i++) {
- x[i] = z[i] * sin((o1*i) / (f1)) * cos((o2*i) / (f2));
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- private: System::Void chart3_Click(System::Object^ sender, System::EventArgs^ e) {
- double A, f1, f2, o1, o2, fs, Ts, f, fi, N;
- int zadanie;
- zadanie = 3;
- A = 1;
- fs = 2500;
- Ts = 1.5;
- N = floor(Ts*fs);
- f = 1 / Ts;
- fi = (3 / 4)*M_PI;
- double *z = new double[N];
- z = FunkcjaZ(A, N, f, fs, fi);
- //B. omega1 < omega2
- double *x = new double[N];
- f1 = 10;
- f2 = 1000;
- o1 = 2 * M_PI * f1;
- o2 = 2 * M_PI * f2;
- for (int i = 0; i <= N; i++) {
- x[i] = z[i] * sin((o1*i) / (f1)) * cos((o2*i) / (f2));
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- private: System::Void chart4_Click(System::Object^ sender, System::EventArgs^ e) {
- double A, f1, o, o2, fs, Ts, f, fi, N;
- int zadanie;
- zadanie = 4;
- A = 1;
- fs = 2500;
- Ts = 1.5;
- N = floor(Ts*fs);
- f = 1 / Ts;
- fi = (3 / 4)*M_PI;
- double *z = new double[N];
- z = FunkcjaZ(A, N, f, fs, fi);
- //C. omega1 = omega2
- double *x = new double[N];
- f1 = 500;
- o = 2 * M_PI * f1;
- for (int i = 0; i <= N; i++) {
- x[i] = z[i] * sin((o*i) / (f1)) * cos((o*i) / (f1));
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- private: System::Void chart5_Click(System::Object^ sender, System::EventArgs^ e) {
- double f, fi, fs, Ts, N;
- int k, zadanie;
- f = 1;
- fs = 2500;
- Ts = 1.5;
- N = floor(Ts*fs);
- k = 8;
- zadanie = 5;
- double *x = new double[N];
- for (int i = 0; i <= N; i++) {
- x[i] = 0.0;
- for (double j = 1; j <= k; j++) {
- x[i] += 1 / (2 * j - 1) * sin((2 * j - 1) * 2 * M_PI * f * (i / fs));
- }
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- private: System::Void chart6_Click(System::Object^ sender, System::EventArgs^ e) {
- double f, fi, fs, Ts, N;
- int k, zadanie;
- f = 1;
- fs = 2500;
- Ts = 1.5;
- N = floor(Ts*fs);
- k = 16;
- zadanie = 6;
- double *x = new double[N];
- for (int i = 0; i <= N; i++) {
- x[i] = 0.0;
- for (double j = 1; j <= k; j++) {
- x[i] += 1 / (2 * j - 1) * sin((2 * j - 1) * 2 * M_PI * f * (i / fs));
- }
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- private: System::Void chart7_Click(System::Object^ sender, System::EventArgs^ e) {
- double f, fi, fs, Ts, N;
- int k, zadanie;
- f = 1;
- fs = 2500;
- Ts = 1.5;
- N = floor(Ts*fs);
- k = 32;
- zadanie = 7;
- double *x = new double[N];
- for (int i = 0; i <= N; i++) {
- x[i] = 0.0;
- for (double j = 1; j <= k; j++) {
- x[i] += 1 / (2 * j - 1) * sin((2 * j - 1) * 2 * M_PI * f * (i / fs));
- }
- }
- Widmo(fs, x, fi, N, zadanie);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement