From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Aufgabenblatt1/DFTApp/.cproject | 949 +++++++++++++++++++++ .../Aufgabenblatt1/DFTApp/.project | 82 ++ .../Aufgabenblatt1/DFTApp/spectrum.gnumeric | Bin 0 -> 17519 bytes .../Aufgabenblatt1/DFTApp/spectrum.plt | 23 + .../Aufgabenblatt1/DFTApp/src/DFTAppController.cpp | 129 +++ .../Aufgabenblatt1/DFTApp/src/DFTAppController.h | 40 + .../Aufgabenblatt1/DFTApp/src/DFTAppParameters.h | 38 + .../Aufgabenblatt1/DFTApp/src/DFTProcessor.cpp | 167 ++++ .../Aufgabenblatt1/DFTApp/src/DFTProcessor.h | 62 ++ .../Aufgabenblatt1/DFTApp/src/Util.h | 89 ++ .../Aufgabenblatt1/DFTApp/src/main.cpp | 21 + .../Aufgabenblatt1/DFTApp/ui/dftapp.glade | 225 +++++ .../Aufgabenblatt1/L\303\266sung.txt" | 10 + .../Aufgabenblatt1/MuS_Aufgabenblatt_1_SS_11.pdf | Bin 0 -> 276805 bytes .../Aufgabenblatt1/Quantization/.cproject | 945 ++++++++++++++++++++ .../Aufgabenblatt1/Quantization/.project | 82 ++ .../Quantization/src/Quantization.cpp | 103 +++ .../Aufgabenblatt1/Quantization/src/Quantization.h | 45 + .../Quantization/src/QuantizationController.cpp | 95 +++ .../Quantization/src/QuantizationController.h | 51 ++ .../Quantization/src/QuantizationParameters.h | 55 ++ .../Aufgabenblatt1/Quantization/src/main.cpp | 22 + .../Quantization/ui/quantization.glade | 216 +++++ .../Aufgabenblatt1/README | 11 + .../Aufgabenblatt1/SineGenerator/.cproject | 615 +++++++++++++ .../Aufgabenblatt1/SineGenerator/.project | 82 ++ .../SineGenerator/src/MainController.cpp | 112 +++ .../SineGenerator/src/MainController.h | 54 ++ .../SineGenerator/src/SineGenerator.cpp | 114 +++ .../SineGenerator/src/SineGenerator.h | 38 + .../SineGenerator/src/SineGeneratorParameters.h | 112 +++ .../Aufgabenblatt1/SineGenerator/src/Util.h | 62 ++ .../Aufgabenblatt1/SineGenerator/src/main.cpp | 23 + .../Aufgabenblatt1/SineGenerator/ui/sinegen.glade | 321 +++++++ .../Aufgabenblatt1/Superposition/.cproject | 946 ++++++++++++++++++++ .../Aufgabenblatt1/Superposition/.project | 82 ++ .../Superposition/src/SuperpositionController.cpp | 104 +++ .../Superposition/src/SuperpositionController.h | 48 ++ .../Superposition/src/SuperpositionParameters.h | 65 ++ .../Superposition/src/WavefileSuperposition.cpp | 77 ++ .../Superposition/src/WavefileSuperposition.h | 21 + .../Aufgabenblatt1/Superposition/src/main.cpp | 21 + .../Aufgabenblatt1/Superposition/ui/superpos.glade | 343 ++++++++ .../Aufgabenblatt1/Testdatei 3 kHz 1.wav | Bin 0 -> 160044 bytes .../Aufgabenblatt1/Testdatei 3 kHz 2.wav | Bin 0 -> 160044 bytes .../Testdatei 3 kHz superponiert.wav | Bin 0 -> 160044 bytes .../Aufgabenblatt1/Testdatei 400 Hz 1.wav | Bin 0 -> 160044 bytes .../Aufgabenblatt1/Testdatei 400 Hz 2.wav | Bin 0 -> 160044 bytes .../Aufgabenblatt1/Testdatei 400 Hz elim.wav | Bin 0 -> 160044 bytes .../Testdatei 400 Hz superponiert.wav | Bin 0 -> 160044 bytes .../Testdatei Sprache 1bit quant.wav | Bin 0 -> 428078 bytes .../Testdatei Sprache 4bit quant.wav | Bin 0 -> 428078 bytes .../Testdatei Sprache 8bit quant.wav | Bin 0 -> 428078 bytes .../Aufgabenblatt1/Testdatei Sprache 8kHz.wav | Bin 0 -> 428076 bytes .../Aufgabenblatt1/Testdatei Sprache.wav | Bin 0 -> 428076 bytes .../Aufgabenblatt1/WaveAnalyzer/.cproject | 945 ++++++++++++++++++++ .../Aufgabenblatt1/WaveAnalyzer/.project | 82 ++ .../org.eclipse.ltk.core.refactoring.prefs | 3 + .../Aufgabenblatt1/WaveAnalyzer/src/Util.h | 32 + .../WaveAnalyzer/src/WaveAnalyzer.cpp | 158 ++++ .../Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.h | 33 + .../WaveAnalyzer/src/WaveAnalyzerController.cpp | 128 +++ .../WaveAnalyzer/src/WaveAnalyzerController.h | 53 ++ .../Aufgabenblatt1/WaveAnalyzer/src/main.cpp | 22 + .../WaveAnalyzer/ui/waveanalyzer.glade | 512 +++++++++++ .../Aufgabenblatt1/fftfile | 517 +++++++++++ .../Aufgabenblatt1/ifftx.wav | Bin 0 -> 846 bytes .../Aufgabenblatt1/mus-eisenhauer-abgabe1.zip | Bin 0 -> 722268 bytes .../Aufgabenblatt1/wave_fft.m | 53 ++ .../Aufgabenblatt1/x.wav | Bin 0 -> 846 bytes 70 files changed, 9238 insertions(+) create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.cproject create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.project create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.gnumeric create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.plt create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppParameters.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/Util.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/main.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/ui/dftapp.glade create mode 100644 "Master/Modellbildung_und_Simulation/Aufgabenblatt1/L\303\266sung.txt" create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/MuS_Aufgabenblatt_1_SS_11.pdf create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/README create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.cproject create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.project create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGeneratorParameters.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/Util.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/main.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/ui/sinegen.glade create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.cproject create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.project create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionParameters.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/main.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/ui/superpos.glade create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 1.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 2.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz superponiert.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 1.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 2.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz elim.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz superponiert.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 1bit quant.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 4bit quant.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8bit quant.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8kHz.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.cproject create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.project create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.settings/org.eclipse.ltk.core.refactoring.prefs create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/Util.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/main.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/ui/waveanalyzer.glade create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/fftfile create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/ifftx.wav create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/mus-eisenhauer-abgabe1.zip create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/wave_fft.m create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/x.wav (limited to 'Master/Modellbildung_und_Simulation/Aufgabenblatt1') diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.cproject b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.cproject new file mode 100644 index 0000000..bc322ed --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.cproject @@ -0,0 +1,949 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.project b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.project new file mode 100644 index 0000000..3dd0921 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/.project @@ -0,0 +1,82 @@ + + + DFTApp + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/DFTApp/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.gnumeric b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.gnumeric new file mode 100644 index 0000000..b8b4973 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.gnumeric differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.plt b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.plt new file mode 100644 index 0000000..ab4eaf1 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/spectrum.plt @@ -0,0 +1,23 @@ +set terminal wxt +set terminal wxt font "/Library/Fonts/Sans Serif, 11" +set multiplot +set size 1.0,0.5 +set datafile separator ";" +set xlabel "freq. [Hz]" +set origin 0.0,0.0 +plot "spectrum.csv" using 1:2 title "Amplitude" with lines +set origin 0.0,0.5 +plot "spectrum.csv" using 1:3 lt 3 title "Phase" with lines +unset multiplot + +set output "spectrum.png" +set terminal png font "/Library/Fonts/Sans Serif, 11" +set multiplot +set size 1.0,0.5 +set datafile separator ";" +set xlabel "freq. [Hz]" +set origin 0.0,0.0 +plot "spectrum.csv" using 1:2 title "Amplitude" with lines +set origin 0.0,0.5 +plot "spectrum.csv" using 1:3 lt 3 title "Phase" with lines +replot diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.cpp new file mode 100644 index 0000000..b66c987 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.cpp @@ -0,0 +1,129 @@ +/* + * DFTAppController.cpp + * + * Created on: 29.04.2011 + * Author: sven + */ +#ifndef DFTAPPCONTROLLER_H_ + #include "DFTAppController.h" +#endif + +#ifndef DFTPROCESSOR_H_ + #include "DFTProcessor.h" +#endif + +#ifndef UTIL_H_ + #include "Util.h" +#endif + +#ifndef _LIBGLADEMM_XML_H + #include +#endif + +#include + +// because of static +const char* DFTAppController::UI_FILENAME = "ui/dftapp.glade"; + +DFTAppController::DFTAppController() { + try { + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("mainwindow",mPtrMainWin); + builder->get_widget("inputfileentry",mPtrInputFileEntry); + builder->get_widget("numsamplesentry",mPtrNumSamplesEntry); + builder->get_widget("startbtn",mPtrStartBtn); + builder->get_widget("openinputfilebtn",mPtrOpenBtn); + builder->get_widget("textview1",mPtrTextView); + } catch (Gtk::BuilderError err) { + std::cout << "Builder Error: " << err.code() << std::endl; + } + mRefPtrTextBuffer = Gtk::TextBuffer::create(); + mPtrTextView->set_buffer(mRefPtrTextBuffer); + mPtrMainWin->signal_hide().connect(sigc::ptr_fun(&Gtk::Main::quit)); + mPtrOpenBtn->signal_clicked().connect(sigc::mem_fun(this,&DFTAppController::on_button_open)); + mPtrStartBtn->signal_clicked().connect(sigc::mem_fun(this,&DFTAppController::on_button_start)); + mPtrNumSamplesEntry->signal_changed().connect(sigc::mem_fun(this,&DFTAppController::on_numsamples_changed)); + on_numsamples_changed(); +} + +DFTAppController::~DFTAppController() { + // TODO Auto-generated destructor stub +} + +void DFTAppController::startApp(Gtk::Main& kit) +{ + kit.run(*mPtrMainWin); + return; +} + +void DFTAppController::on_button_start() +{ + DFTProcessor dftProc(mParams); + std::string text = "Idx\tInput\tRe\tIm\n"; + const std::vector& inputData = dftProc.getInputData(); + const std::vector& Re = dftProc.getRe(); + const std::vector& Im = dftProc.getIm(); + std::vector::const_iterator inIter = inputData.begin(); + std::vector::const_iterator reIter = Re.begin(); + std::vector::const_iterator imIter = Im.begin(); + unsigned idx = 0; + for (;inIter != inputData.end(); inIter++) + { + if (inIter != inputData.begin()) { + text += "\n"; + } + text += Util::ToUString(idx); + text += "\t"; + text += Util::ToUString((int) *inIter); + if (idx < mParams.getNumSamples() / 2) { + text += "\t"; + text += Util::ToUString(*reIter); + text += "\t"; + text += Util::ToUString(*imIter); + } + reIter++; + imIter++; + idx++; + } + mRefPtrTextBuffer->set_text(text); + std::cout << mRefPtrTextBuffer->get_line_count() << " lines" << std::endl; +} + +void DFTAppController::on_button_open() +{ + std::string filename; + Gtk::FileChooserDialog* ptrFilechooser; + try { + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("filechooserdlg",ptrFilechooser); + } catch (Gtk::BuilderError err) { + std::cout << "Builder Error: " << err.code() << std::endl; + } + Gtk::FileFilter waveFilter; + waveFilter.set_name("Wave files"); + waveFilter.add_pattern("*.wav"); + ptrFilechooser->add_filter(waveFilter); + ptrFilechooser->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + ptrFilechooser->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + ptrFilechooser->set_transient_for(*mPtrMainWin); + int result = ptrFilechooser->run(); + switch (result) + { + case Gtk::RESPONSE_OK: + filename = ptrFilechooser->get_filename(); + mParams.setInputFilename(filename); + mPtrInputFileEntry->set_text(mParams.getInputFilename()); + break; + default: + break; + } + delete ptrFilechooser; +} + +void DFTAppController::on_numsamples_changed() +{ + unsigned numSamples; + Glib::ustring numSamplesStr = mPtrNumSamplesEntry->get_text(); + numSamples = Util::ToUint(numSamplesStr); + mParams.setNumSamples(numSamples); +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.h new file mode 100644 index 0000000..0b2f22e --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppController.h @@ -0,0 +1,40 @@ +/* + * DFTAppController.h + * + * Created on: 29.04.2011 + * Author: sven + */ + +#ifndef DFTAPPCONTROLLER_H_ +#define DFTAPPCONTROLLER_H_ + +#ifndef _GTKMM_H + #include +#endif + +#ifndef DFTAPP_PARAMETERS_H_ + #include "DFTAppParameters.h" +#endif + +class DFTAppController { +public: + DFTAppController(); + virtual ~DFTAppController(); + void startApp(Gtk::Main&); +private: + static const char* UI_FILENAME; + DFTAppParameters mParams; + Gtk::Window* mPtrMainWin; + Gtk::Button* mPtrStartBtn; + Gtk::Button* mPtrOpenBtn; + Gtk::Entry* mPtrInputFileEntry; + Gtk::Entry* mPtrNumSamplesEntry; + Gtk::TextView* mPtrTextView; + Glib::RefPtr mRefPtrTextBuffer; + + void on_button_start(); + void on_button_open(); + void on_numsamples_changed(); +}; + +#endif /* DFTAPPCONTROLLER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppParameters.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppParameters.h new file mode 100644 index 0000000..32c68fe --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTAppParameters.h @@ -0,0 +1,38 @@ +#ifndef DFTAPP_PARAMETERS_H_ +#define DFTAPP_PARAMETERS_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +class DFTAppParameters +{ +public: + +private: + std::string mInputFilename; + unsigned mNumSamples; +public: + const std::string& getInputFilename() const + { + return mInputFilename; + } + + unsigned getNumSamples() const + { + return mNumSamples; + } + + void setInputFilename(std::string& mInputFilename) + { + this->mInputFilename = mInputFilename; + } + + void setNumSamples(unsigned mNumSamples) + { + this->mNumSamples = mNumSamples; + } + +}; + +#endif //DFTAPP_PARAMETERS_H_ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.cpp new file mode 100644 index 0000000..97571f9 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.cpp @@ -0,0 +1,167 @@ +/* + * DFTProcessor.cpp + * + * Created on: 29.04.2011 + * Author: sven + */ +#ifndef DFTPROCESSOR_H_ + #include "DFTProcessor.h" +#endif + +#ifndef _GLIBCXX_IOSTREAM + #include +#endif + +#ifndef _GLIBCXX_FSTREAM + #include +#endif + +#include +#include +#include +#include + +const double PI = 3.14159265358979323846264338327950288419716939; + +const char* ORIG_FILENAME = "orig.wav"; +const char* IDFT_FILENAME = "idft.wav"; + +DFTProcessor::DFTProcessor(DFTAppParameters& params) +:mParams(params) +,mNumDftSamples(mParams.getNumSamples() / 2) +,mInputData(mParams.getNumSamples()) +,mRe(mNumDftSamples) +,mIm(mNumDftSamples) +,mIdft(mParams.getNumSamples()) +{ + std::cout << "DFT processing " << mParams.getNumSamples() << + " samples of" << mParams.getInputFilename() << std::endl; + std::ifstream inFile; + std::ofstream origFile; + std::ofstream idftFile; + inFile.open(mParams.getInputFilename().c_str(), std::ios::in | std::ios::binary); + origFile.open(ORIG_FILENAME, std::ios::out | std::ios::binary); + idftFile.open(IDFT_FILENAME, std::ios::out | std::ios::binary); + int dataStartOffset = 0x2C; + char header[dataStartOffset]; + inFile.read(&header[0],dataStartOffset); + memcpy(&mSampleRate,((&header[0])+0x18),4); + origFile.write((char*) &header[0],dataStartOffset); + idftFile.write((char*) &header[0],dataStartOffset); + short data; + std::cout << "Original file:" << std::endl; + for (unsigned i=0;i::const_iterator specIter; + for(specIter = mSpectrum.begin() ; specIter != mSpectrum.end() ; specIter++) { + const SpectralData& actSpec = *specIter; + if (specIter != mSpectrum.begin()) { + csvFile << std::endl; + } + csvFile << actSpec.mFreq << ";"; + csvFile << std::setprecision (12) << std::fixed << actSpec.mAmplitude; + csvFile << ";"; + csvFile << std::setprecision (12) << std::fixed << actSpec.mPhase; + } + csvFile.close(); +} + +void DFTProcessor::startGnuPlot() +{ + int i = system("gnuplot spectrum.plt -p"); + if (i != 0) { + std::cerr << "Error starting gnuplot: " << i << std::endl; + } +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.h new file mode 100644 index 0000000..96ef46e --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/DFTProcessor.h @@ -0,0 +1,62 @@ +/* + * DFTProcessor.h + * + * Created on: 29.04.2011 + * Author: sven + */ + +#ifndef DFTPROCESSOR_H_ +#define DFTPROCESSOR_H_ + +#ifndef DFTAPP_PARAMETERS_H_ + #include "DFTAppParameters.h" +#endif + +#include + +struct SpectralData +{ + unsigned mFreq; + double mAmplitude; + double mPhase; +}; + +class DFTProcessor { +public: + DFTProcessor(DFTAppParameters&); + virtual ~DFTProcessor(); + const std::vector& getInputData() const + { + return mInputData; + } + const std::vector& getRe() const + { + return mRe; + } + const std::vector& getIm() const + { + return mIm; + } + const std::vector& getIdft() const + { + return mIdft; + } + const std::vector& getSpectrum() const + { + return mSpectrum; + } +private: + DFTAppParameters& mParams; + unsigned mNumDftSamples; + unsigned mSampleRate; + std::vector mInputData; + std::vector mRe; + std::vector mIm; + std::vector mIdft; + std::vector mSpectrum; + + void writeSpectrumToCSV(); + void startGnuPlot(); +}; + +#endif /* DFTPROCESSOR_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/Util.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/Util.h new file mode 100644 index 0000000..c1f7130 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/Util.h @@ -0,0 +1,89 @@ +/* + * Util.h + * + * Created on: 31.03.2011 + * Author: sven + */ + +#ifndef UTIL_H_ +#define UTIL_H_ + +#ifndef _GLIBCXX_SSTREAM + #include +#endif + +#include + +#ifndef _GLIBMM_USTRING_H + #include +#endif + +class Util +{ +public: + static Glib::ustring ToUString(unsigned short val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static Glib::ustring ToUString(short val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static Glib::ustring ToUString(unsigned val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static Glib::ustring ToUString(int val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static Glib::ustring ToUString(double val) + { + std::ostringstream ssIn; + ssIn << std::setprecision(12) << std::fixed << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static unsigned short ToUShort(Glib::ustring& val) + { + std::istringstream buffer(val.raw()); + unsigned short res; + buffer >> res; + return res; + } + + static unsigned ToUint(Glib::ustring& val) + { + std::istringstream buffer(val.raw()); + unsigned res; + buffer >> res; + return res; + } + + static short ToShort(Glib::ustring& val) + { + std::istringstream buffer(val.raw()); + short res; + buffer >> res; + return res; + } +}; + +#endif /* UTIL_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/main.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/main.cpp new file mode 100644 index 0000000..0791767 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/src/main.cpp @@ -0,0 +1,21 @@ +/* + * main.cpp + * + * Created on: 29.04.2011 + * Author: sven + */ +#ifndef DFTAPPCONTROLLER_H_ + #include "DFTAppController.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +int main(int argc,char* argv[]) +{ + Gtk::Main kit(argc,argv); + DFTAppController dftAppController; + dftAppController.startApp(kit); + return 0; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/ui/dftapp.glade b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/ui/dftapp.glade new file mode 100644 index 0000000..ed37e6f --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/DFTApp/ui/dftapp.glade @@ -0,0 +1,225 @@ + + + + + + False + 5 + normal + + + True + False + 2 + + + True + False + end + + + + + + + + + False + True + end + 0 + + + + + + + + + + False + + + True + True + + + True + True + + + 340 + 200 + True + False + 3 + 4 + + + 100 + 27 + True + True + + True + False + False + True + True + + + 2 + 3 + + + + + 100 + 44 + True + False + 0 + num of samples + + + 1 + 2 + 1 + 2 + + + + + 100 + 28 + True + True + + 8000 + True + False + False + True + True + + + 2 + 3 + 1 + 2 + + + + + open + 100 + 28 + True + True + True + False + + + 3 + 4 + + + + + + + start + 100 + 42 + True + True + True + False + 0.47999998927116394 + + + 3 + 4 + 2 + 3 + + + + + + + True + False + 0 + input file + + + 1 + 2 + + + + + + + + + + + + + + + + + + + + + + + False + True + + + + + 300 + True + False + + + True + False + + + + + False + True + + + + + True + True + automatic + automatic + + + 400 + 600 + True + True + + + + + True + True + + + + + + diff --git "a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/L\303\266sung.txt" "b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/L\303\266sung.txt" new file mode 100644 index 0000000..78042ba --- /dev/null +++ "b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/L\303\266sung.txt" @@ -0,0 +1,10 @@ +Aufgabe 3: +Lsung: nderung der Datei an Offset 0x18 von 80 3e 00 00 in 40 1f 00 00 +Beschreibung: Die Sprache klingt tiefer und langsamer. + +Aufgabe 4: +Die 1bit quantisierte Datei klingt stark verrauscht und dumpf. +Bereits eine 8bit Quantisierung klingt deutlich besser. + +Aufgabe 8: +Interessantes Phasenspektrum bei Testdatei 3kHz superponiert und 1000 DFT-Samples \ No newline at end of file diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/MuS_Aufgabenblatt_1_SS_11.pdf b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/MuS_Aufgabenblatt_1_SS_11.pdf new file mode 100644 index 0000000..e6184bf Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/MuS_Aufgabenblatt_1_SS_11.pdf differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject new file mode 100644 index 0000000..61aefe9 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject @@ -0,0 +1,945 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project new file mode 100644 index 0000000..68f108b --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project @@ -0,0 +1,82 @@ + + + Quantization + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/Quantization/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp new file mode 100644 index 0000000..9198223 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp @@ -0,0 +1,103 @@ +/* + * Quantization.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATION_H_ + #include "Quantization.h" +#endif + +#ifndef _GLIBCXX_FSTREAM + #include +#endif + +#ifndef _GLIBCXX_NUMERIC_LIMITS + #include +#endif + +#ifndef _GLIBCXX_CMATH + #include +#endif + +#ifndef _GLIBCXX_IOSTREAM + #include +#endif + +Quantization::Quantization(QuantizationParameters& params) +:mParams(params) +{ + calcQuantizationValues(); + std::ifstream inFile; + std::ofstream outFile; + inFile.open(mParams.getInputFile().c_str(), std::ios::in | std::ios::binary ); + outFile.open(mParams.getOutputFile().c_str(), std::ios::out | std::ios::binary); + int dataLenOffset = 0x28; + char header[dataLenOffset]; + inFile.read(&header[0],dataLenOffset); + outFile.write(&header[0],dataLenOffset); + int numSamples = 0; + inFile.read((char*) &numSamples,sizeof(numSamples)); + outFile.write((char*) &numSamples,sizeof(numSamples)); + short data; + short quantizationized; +// unsigned counter = 0; + for (int i=0; i < numSamples;) { + inFile.read((char*) &data, sizeof(data) ); + quantizationized = getQuantizationValue(data); + outFile.write((char*) &quantizationized, sizeof(quantizationized) ); +// std::cout << counter++ << " " << quantizationized << std::endl; + i += sizeof(short); + } + inFile.close(); + outFile.close(); + std::cout << "quantization done" << std::endl; +} + +Quantization::~Quantization() +{ + QuantizationRangesIter it = mQuantizationRanges.begin(); + for ( ;it < mQuantizationRanges.end(); ) + { + delete *it++; + } + mQuantizationRanges.clear(); +} + +short Quantization::getQuantizationValue(short val) +{ + // shift to unsigned posivitives values + unsigned short shiftedVal = val - std::numeric_limits::min(); + QuantizationRangesIter it = mQuantizationRanges.begin(); + for(; it < mQuantizationRanges.end(); it++) { + QuantizationRange* quantRangePtr = *it; + if (quantRangePtr->IsInRange(shiftedVal)) { + // shift back + return quantRangePtr->mRangeValue + std::numeric_limits::min(); + } + } + std::cout << val << " " << shiftedVal << " not quantizationized" << std::endl; + return -1; +} + +void Quantization::calcQuantizationValues() +{ + mNumQuantizationValues = 1 << mParams.getBits(); +// std::cout << mNumQuantizationValues << " quantization values" << std::endl; + unsigned short valueRangeWidth = std::numeric_limits::max() / mNumQuantizationValues; +// std::cout << "value range width " << valueRangeWidth << std::endl; + unsigned short rangeMiddle = valueRangeWidth / 2; +// std::cout << "value range middle " << rangeMiddle << std::endl; + QuantizationRange* quantRangePtr = NULL; + for (unsigned i=0; imMinValue = i * valueRangeWidth; + quantRangePtr->mMaxValue = ((i+1) * valueRangeWidth) - 1; + quantRangePtr->mRangeValue = quantRangePtr->mMinValue + rangeMiddle; + quantRangePtr->mRangeWidth = valueRangeWidth; +// std::cout << "quantization value "<< (i+1) << ": " << quantRangePtr->mRangeValue << std::endl; +// std::cout << "Range: "<< quantRangePtr->mMinValue << " - " << quantRangePtr->mMaxValue << std::endl; + mQuantizationRanges.push_back(quantRangePtr); + } +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h new file mode 100644 index 0000000..5939591 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h @@ -0,0 +1,45 @@ +/* + * Quantization.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATION_H_ +#define QUANTIZATION_H_ + +#ifndef QUANTIZATIONPARAMETERS_H_ + #include "QuantizationParameters.h" +#endif + +#ifndef _GLIBCXX_VECTOR + #include +#endif + +struct QuantizationRange { + unsigned short mMinValue; + unsigned short mMaxValue; + unsigned short mRangeWidth; + unsigned short mRangeValue; + bool IsInRange(unsigned short val) + { + return ((val >= mMinValue) && (val <= mMaxValue)); + } +}; + +typedef std::vector QuantizationRanges; +typedef std::vector::iterator QuantizationRangesIter; + +class Quantization { +public: + Quantization(QuantizationParameters& params); + virtual ~Quantization(); +private: + QuantizationParameters& mParams; + unsigned mNumQuantizationValues; + QuantizationRanges mQuantizationRanges; + short getQuantizationValue(short); + void calcQuantizationValues(); +}; + +#endif /* QUANTIZATION_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp new file mode 100644 index 0000000..47196bd --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp @@ -0,0 +1,95 @@ +/* + * QuantizationController.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ +#ifndef QUANTIZATIONCONTROLLER_H_ + #include "QuantizationController.h" +#endif + +#ifndef QUANTIZATION_H_ + #include "Quantization.h" +#endif + +const char* QuantizationController::UI_FILENAME = "ui/quantization.glade"; +const double QuantizationController::QUANTIZATIONBITS_DEFAULT = 8.0; +const double QuantizationController::QUANTIZATIONBITS_MIN = 1.0; +const double QuantizationController::QUANTIZATIONBITS_MAX = 16.0; + +QuantizationController::QuantizationController() +:mQuantizationBitsAdj(QUANTIZATIONBITS_DEFAULT,QUANTIZATIONBITS_MIN,QUANTIZATIONBITS_MAX) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("mainwindow",mPtrMainWin); + builder->get_widget("quantizationbits",mPtrQuantizationBits); + builder->get_widget("openinputbtn",mPtrOpenInputBtn); + builder->get_widget("openoutputbtn",mPtrOpenOutputBtn); + builder->get_widget("startbtn",mPtrStartBtn); + builder->get_widget("inputfile",mPtrInputFile); + builder->get_widget("outputfile",mPtrOutputFile); + mPtrQuantizationBits->set_adjustment(mQuantizationBitsAdj); + mPtrStartBtn->signal_clicked().connect(sigc::mem_fun(this,&QuantizationController::on_start_btn)); + mPtrOpenInputBtn->signal_clicked().connect(sigc::mem_fun(this,&QuantizationController::on_open_input_btn)); + mPtrOpenOutputBtn->signal_clicked().connect(sigc::mem_fun(this,&QuantizationController::on_open_output_btn)); + mPtrQuantizationBits->signal_value_changed().connect(sigc::mem_fun(this,&QuantizationController::on_quantizationbits_changed)); + mParams.setBits(mPtrQuantizationBits->get_value_as_int()); +} + +QuantizationController::~QuantizationController() { + // TODO Auto-generated destructor stub +} +void QuantizationController::startApp(Gtk::Main& kit) +{ + kit.run(*mPtrMainWin); +} + +void QuantizationController::on_open_input_btn() +{ + std::string filename; + choose_file(filename); + mParams.setInputFile(filename); + mPtrInputFile->set_text(mParams.getInputFile()); +} + +void QuantizationController::on_open_output_btn() +{ + std::string filename; + choose_file(filename); + mParams.setOutputFile(filename); + mPtrOutputFile->set_text(mParams.getOutputFile()); +} + +void QuantizationController::on_quantizationbits_changed() +{ + mParams.setBits(mPtrQuantizationBits->get_value_as_int()); +} + +void QuantizationController::on_start_btn() +{ + Quantization quantization(mParams); +} + +void QuantizationController::choose_file(std::string& filename) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + Gtk::FileChooserDialog* ptrFilechooser; + builder->get_widget("filechooserdialog",ptrFilechooser); + Gtk::FileFilter waveFilter; + waveFilter.set_name("Wave files"); + waveFilter.add_pattern("*.wav"); + ptrFilechooser->add_filter(waveFilter); + ptrFilechooser->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + ptrFilechooser->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + ptrFilechooser->set_transient_for(*mPtrMainWin); + int result = ptrFilechooser->run(); + switch (result) + { + case Gtk::RESPONSE_OK: + filename = ptrFilechooser->get_filename(); + break; + default: + break; + } + delete ptrFilechooser; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h new file mode 100644 index 0000000..ea19c64 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h @@ -0,0 +1,51 @@ +/* + * QuantizationController.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATIONCONTROLLER_H_ +#define QUANTIZATIONCONTROLLER_H_ + +#ifndef QUANTIZATIONPARAMETERS_H_ + #include "QuantizationParameters.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +#ifndef _GLIBCXX_STRING + #include +#endif + +class QuantizationController { +public: + QuantizationController(); + virtual ~QuantizationController(); + void startApp(Gtk::Main& kit); +private: + static const char* UI_FILENAME; + static const double QUANTIZATIONBITS_DEFAULT; + static const double QUANTIZATIONBITS_MIN; + static const double QUANTIZATIONBITS_MAX; + Gtk::Window* mPtrMainWin; + Gtk::Entry* mPtrInputFile; + Gtk::Entry* mPtrOutputFile; + Gtk::SpinButton* mPtrQuantizationBits; + Gtk::Button* mPtrOpenInputBtn; + Gtk::Button* mPtrOpenOutputBtn; + Gtk::Button* mPtrStartBtn; + + Gtk::Adjustment mQuantizationBitsAdj; + QuantizationParameters mParams; + + void on_open_input_btn(); + void on_open_output_btn(); + void on_start_btn(); + void on_quantizationbits_changed(); + void choose_file(std::string&); +}; + +#endif /* QUANTIZATIONCONTROLLER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h new file mode 100644 index 0000000..06be668 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h @@ -0,0 +1,55 @@ +/* + * QuantizationParameters.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATIONPARAMETERS_H_ +#define QUANTIZATIONPARAMETERS_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +class QuantizationParameters +{ +public: +private: + std::string mInputFile; + std::string mOutputFile; + int mBits; +public: + int getBits() const + { + return mBits; + } + + std::string getInputFile() const + { + return mInputFile; + } + + std::string getOutputFile() const + { + return mOutputFile; + } + + void setBits(int mBits) + { + this->mBits = mBits; + } + + void setInputFile(std::string& mInputFile) + { + this->mInputFile = mInputFile; + } + + void setOutputFile(std::string& mOutputFile) + { + this->mOutputFile = mOutputFile; + } + +}; + +#endif /* QUANTIZATIONPARAMETERS_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp new file mode 100644 index 0000000..7257265 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp @@ -0,0 +1,22 @@ +/* + * main.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATIONCONTROLLER_H_ + #include "QuantizationController.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +int main(int argc, char* argv[]) +{ + Gtk::Main kit(argc,argv); + QuantizationController quantCtrl; + quantCtrl.startApp(kit); + return 0; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade new file mode 100644 index 0000000..ac30962 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade @@ -0,0 +1,216 @@ + + + + + + Quantization + + + True + 5 + 5 + + + True + 0 + Input wave file + + + 1 + 2 + 1 + 2 + + + + + True + 0 + Quantization (bit) + + + 1 + 2 + 2 + 3 + + + + + True + 0 + Output wave file + + + 1 + 2 + 3 + 4 + + + + + True + True + + + + 2 + 3 + 2 + 3 + + + + + 480 + True + True + False + + + + 2 + 3 + 1 + 2 + + + + + True + True + False + + + + 2 + 3 + 3 + 4 + + + + + ... + True + True + True + + + 3 + 4 + 1 + 2 + + + + + ... + True + True + True + + + 3 + 4 + 3 + 4 + + + + + Start + True + True + True + + + 3 + 4 + 4 + 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + normal + + + True + 2 + + + + + + True + end + + + + + + + + + False + end + 0 + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/README b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/README new file mode 100644 index 0000000..eeba059 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/README @@ -0,0 +1,11 @@ +Basis-System: + - Ubuntu 11.04 mit g++, make, build-essential und Eclipse CDT + - gnuplot + +Weitere Entwicklungspakete: + - libgtkmm-2.4-dev + - libglademm-2.4-dev + +Die einzelnen Projekte müssen in Eclipse CDT importiert werden. +Dort lassen sie sich mittels "build project" übersetzen. + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.cproject b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.cproject new file mode 100644 index 0000000..530b9a2 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.cproject @@ -0,0 +1,615 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.project b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.project new file mode 100644 index 0000000..694de74 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/.project @@ -0,0 +1,82 @@ + + + SineGenerator + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/SineGenerator/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.cpp new file mode 100644 index 0000000..ed602fd --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.cpp @@ -0,0 +1,112 @@ +/* + * MainController.cpp + * + * Created on: 31.03.2011 + * Author: sven + */ +#ifndef MAINCONTROLLER_H_ + #include "MainController.h" +#endif +#ifndef UTIL_H_ + #include "Util.h" +#endif +#ifndef SINEGENERATOR_H_ + #include "SineGenerator.h" +#endif +#ifndef _LIBGLADEMM_XML_H + #include +#endif + +const unsigned short MainController::DEFAULT_FREQUENCY = 400; +const unsigned short MainController::DEFAULT_AMPLITUDE = 100; +const unsigned short MainController::DEFAULT_PHASE = 0; +const unsigned short MainController::DEFAULT_LENGTH = 5; +const char* MainController::DEFAULT_WAVEFILENAME = "test.wav"; +const char* MainController::UI_FILENAME="ui/sinegen.glade"; + +MainController::MainController() +: + mParams( + DEFAULT_FREQUENCY + ,DEFAULT_AMPLITUDE + ,DEFAULT_PHASE + ,DEFAULT_LENGTH + ,DEFAULT_WAVEFILENAME + ) + ,mFreqAdj(static_cast(mParams.getFrequency()),1.0,8000.0) + ,mAmpAdj(static_cast(mParams.getAmplitude()),1.0,100.0) + ,mPhaseAdj(static_cast(mParams.getPhase()),-180.0,180.0) + ,mLengthAdj(static_cast(mParams.getLength()),1.0,60.0) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("mainwindow",mPtrMainWin); + builder->get_widget("freqField",mPtrFreqField); + builder->get_widget("ampField",mPtrAmpField); + builder->get_widget("phaseField",mPtrPhaseField); + builder->get_widget("lenField",mPtrLengthField); + builder->get_widget("bitrateentry",mPtrBitrateEntry); + builder->get_widget("samplerateentry",mPtrSamplerateEntry); + builder->get_widget("filenameentry",mPtrFilenameEntry); + builder->get_widget("startbutton",mPtrStartBtn); + mPtrAmpField->set_adjustment(mAmpAdj); + mPtrFreqField->set_adjustment(mFreqAdj); + mPtrPhaseField->set_adjustment(mPhaseAdj); + mPtrLengthField->set_adjustment(mLengthAdj); + mPtrBitrateEntry->set_text(Util::ToUString(mParams.getBitrate())); + mPtrSamplerateEntry->set_text(Util::ToUString(mParams.getSamplerate())); + mPtrFilenameEntry->set_text(mParams.getFilename()); + + mPtrMainWin->signal_hide().connect(sigc::ptr_fun(&Gtk::Main::quit)); + mPtrStartBtn->signal_clicked().connect(sigc::mem_fun(this,&MainController::on_startbutton_clicked)); + + mPtrFreqField->signal_value_changed().connect(sigc::mem_fun(this,&MainController::on_freq_changed)); + mPtrAmpField->signal_value_changed().connect(sigc::mem_fun(this,&MainController::on_amp_changed)); + mPtrPhaseField->signal_value_changed().connect(sigc::mem_fun(this,&MainController::on_phase_changed)); + mPtrLengthField->signal_value_changed().connect(sigc::mem_fun(this,&MainController::on_length_changed)); + mPtrFilenameEntry->signal_changed().connect(sigc::mem_fun(this,&MainController::on_filename_changed)); +} + +MainController::~MainController() { + +} + +void MainController::startApp(Gtk::Main& kit) +{ + kit.run(*mPtrMainWin); +} + +void MainController::on_startbutton_clicked() +{ + SineGenerator gen(mParams); + gen.generateWavefile(); +} + +void MainController::on_freq_changed() +{ + Glib::ustring utxt = mPtrFreqField->get_text(); + mParams.setFrequency(Util::ToUShort(utxt)); +} + +void MainController::on_amp_changed() +{ + Glib::ustring buffer = mPtrAmpField->get_text(); + mParams.setAmplitude(Util::ToUShort(buffer)); +} + +void MainController::on_phase_changed() +{ + Glib::ustring buffer = mPtrPhaseField->get_text(); + mParams.setPhase(Util::ToShort(buffer)); +} + +void MainController::on_length_changed() +{ + Glib::ustring buffer = mPtrLengthField->get_text(); + mParams.setLength(Util::ToUShort(buffer)); +} + +void MainController::on_filename_changed() +{ + std::string buffer = mPtrFilenameEntry->get_text().raw(); + mParams.setFilename(buffer); +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.h new file mode 100644 index 0000000..6852e51 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/MainController.h @@ -0,0 +1,54 @@ +/* + * MainController.h + * + * Created on: 31.03.2011 + * Author: sven + */ + +#ifndef MAINCONTROLLER_H_ +#define MAINCONTROLLER_H_ + +#ifndef SINEGENERATORPARAMETERS_H_ + #include "SineGeneratorParameters.h" +#endif +#ifndef _GTKMM_H + #include +#endif + +class MainController { +public: + MainController(); + virtual ~MainController(); + void startApp(Gtk::Main&); +private: + static const unsigned short DEFAULT_FREQUENCY; + static const unsigned short DEFAULT_AMPLITUDE; + static const unsigned short DEFAULT_PHASE; + static const unsigned short DEFAULT_LENGTH; + static const char* DEFAULT_WAVEFILENAME; + static const char* UI_FILENAME; + + Gtk::Window* mPtrMainWin; + Gtk::SpinButton* mPtrFreqField; + Gtk::SpinButton* mPtrAmpField; + Gtk::SpinButton* mPtrPhaseField; + Gtk::SpinButton* mPtrLengthField; + Gtk::Entry* mPtrBitrateEntry; + Gtk::Entry* mPtrSamplerateEntry; + Gtk::Entry* mPtrFilenameEntry; + Gtk::Button* mPtrStartBtn; + SineGeneratorParameters mParams; + Gtk::Adjustment mFreqAdj; + Gtk::Adjustment mAmpAdj; + Gtk::Adjustment mPhaseAdj; + Gtk::Adjustment mLengthAdj; + + void on_startbutton_clicked(); + void on_freq_changed(); + void on_amp_changed(); + void on_phase_changed(); + void on_length_changed(); + void on_filename_changed(); +}; + +#endif /* MAINCONTROLLER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.cpp new file mode 100644 index 0000000..922c44b --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.cpp @@ -0,0 +1,114 @@ +/* + * SineGenerator.cpp + * + * Created on: 31.03.2011 + * Author: sven + */ +#ifndef SINEGENERATOR_H_ + #include "SineGenerator.h" +#endif +#ifndef _GLIBCXX_IOSTREAM + #include +#endif +#ifndef _GLIBCXX_CMATH + #include +#endif +#ifndef _GLIBCXX_NUMERIC_LIMITS + #include +#endif +#ifndef _STRING_H + #include +#endif +const double SineGenerator::PI=3.141592654; + +SineGenerator::SineGenerator(SineGeneratorParameters& params) +:mParams(params) +{ +} + +SineGenerator::~SineGenerator() { +} + +void SineGenerator::generateWavefile() +{ + std::cout << "Freq: " << mParams.getFrequency() + << " Amp: " << mParams.getAmplitude() + << " Phase: " << mParams.getPhase() + << " Length: " << mParams.getLength() + << " File: " << mParams.getFilename() + << std::endl; + + std::ofstream wavefile; + wavefile.open(mParams.getFilename().c_str(), std::ios::out | std::ios::binary); + int filestart = wavefile.tellp(); + writeWaveHeader(wavefile); + writeWaveData(wavefile); + int fileend = wavefile.tellp(); + int filesize = fileend-filestart-8; + wavefile.seekp(0x4); + wavefile.write((char*) &filesize,sizeof(filesize)); + wavefile.close(); + std::cout << mParams.getFilename() << " written" << std::endl; +} + +void SineGenerator::writeWaveHeader(std::ofstream& wavefile) +{ + const char* riff = "RIFF"; + const char* wave = "WAVE"; + const char* fmt = "fmt "; + int size = 0; + int fmtLen = 16; + short fmtTag = 0x0001; + short channels = 0x0001; + int sampleRate = mParams.getSamplerate(); + short bitsPerSample = mParams.getBitrate(); + short blockAlign = channels * (bitsPerSample / 8); + int bytesPerSecond = sampleRate * blockAlign; + + wavefile.write(riff,strlen(riff)); + wavefile.write((char*)&size,sizeof(size)); + wavefile.write(wave,strlen(wave)); + wavefile.write(fmt,strlen(fmt)); + wavefile.write((char*) &fmtLen,sizeof(fmtLen)); + wavefile.write((char*) &fmtTag,sizeof(fmtTag)); + wavefile.write((char*) &channels,sizeof(channels)); + wavefile.write((char*) &sampleRate,sizeof(sampleRate)); + wavefile.write((char*) &bytesPerSecond,sizeof(bytesPerSecond)); + wavefile.write((char*) &blockAlign,sizeof(blockAlign)); + wavefile.write((char*) &bitsPerSample,sizeof(bitsPerSample)); +} + +void SineGenerator::writeWaveData(std::ofstream& wavefile) +{ + generateData(); + const char* data = "data"; + int dataLen = mData.size() * sizeof(short); + short actData = 0; + DataIter dataIter; + wavefile.write(data,strlen(data)); + wavefile.write((char*) &dataLen,(sizeof(dataLen))); + for (dataIter = mData.begin(); dataIter != mData.end(); dataIter++) + { + actData = *dataIter; + wavefile.write((char*) &actData,(sizeof(actData))); + } +} + +void SineGenerator::generateData() +{ + double actData = 0.0; + double amp = (double)(mParams.getAmplitude()) * ((double) std::numeric_limits::max()) / 100.0; + double phaseRad = (double)(mParams.getPhase()) * PI / 180.0; + double freq = (double)(mParams.getFrequency()); + double twoPi = 2.0 * PI; + short actShort; + for (short second = 0; second < mParams.getLength(); second++) { + for(unsigned short actTime = 0; actTime < mParams.getSamplerate(); actTime++) + { + actData = amp * std::sin((twoPi * freq * ((double) (actTime) / (double) mParams.getSamplerate() ) ) + phaseRad); + actShort = (short) std::floor(actData+.5); + //std::cout << actTime << ". " << actData << " " << actShort << std::endl; + mData.push_back(actShort); + } + } +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.h new file mode 100644 index 0000000..d946bfa --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGenerator.h @@ -0,0 +1,38 @@ +/* + * SineGenerator.h + * + * Created on: 31.03.2011 + * Author: sven + */ + +#ifndef SINEGENERATOR_H_ +#define SINEGENERATOR_H_ + +#ifndef SINEGENERATORPARAMETERS_H_ + #include "SineGeneratorParameters.h" +#endif +#ifndef _GLIBCXX_FSTREAM + #include +#endif +#ifndef _GLIBCXX_VECTOR + #include +#endif + +typedef std::vector WaveData; +typedef WaveData::iterator DataIter; + +class SineGenerator { +public: + SineGenerator(SineGeneratorParameters&); + virtual ~SineGenerator(); + void generateWavefile(); +private: + static const double PI; + SineGeneratorParameters& mParams; + WaveData mData; + void writeWaveHeader(std::ofstream&); + void writeWaveData(std::ofstream&); + void generateData(); +}; + +#endif /* SINEGENERATOR_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGeneratorParameters.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGeneratorParameters.h new file mode 100644 index 0000000..fba6142 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/SineGeneratorParameters.h @@ -0,0 +1,112 @@ +/* + * SineGeneratorParameters.h + * + * Created on: 31.03.2011 + * Author: sven + */ + +#ifndef SINEGENERATORPARAMETERS_H_ +#define SINEGENERATORPARAMETERS_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +const unsigned short DEFAULT_BITRATE = 16; +const unsigned short DEFAULT_SAMPLERATE = 16000; + +class SineGeneratorParameters { +public: + SineGeneratorParameters() + :mBitrate(DEFAULT_BITRATE),mSamplerate(DEFAULT_SAMPLERATE) {} + + SineGeneratorParameters( + unsigned short freq, + unsigned short amp, + short phase, + unsigned short length + ,const char* filename) + : + mFrequency(freq) + ,mAmplitude(amp) + ,mPhase(phase) + ,mLength(length) + ,mBitrate(DEFAULT_BITRATE) + ,mSamplerate(DEFAULT_SAMPLERATE) + ,mFilename(filename) + { + } + + virtual ~SineGeneratorParameters() {} + + unsigned short getLength() const + { + return mLength; + } + + void setLength(unsigned short mLength) + { + this->mLength = mLength; + } + + unsigned short getAmplitude() const + { + return mAmplitude; + } + + unsigned short getBitrate() const + { + return mBitrate; + } + + std::string getFilename() const + { + return mFilename; + } + + unsigned short getFrequency() const + { + return mFrequency; + } + + short getPhase() const + { + return mPhase; + } + + unsigned short getSamplerate() const + { + return mSamplerate; + } + + void setAmplitude(unsigned short mAmplitude) + { + this->mAmplitude = mAmplitude; + } + + void setFilename(std::string& mFilename) + { + this->mFilename = mFilename; + } + + void setFrequency(unsigned short mFrequency) + { + this->mFrequency = mFrequency; + } + + void setPhase(short mPhase) + { + this->mPhase = mPhase; + } + +private: + unsigned short mFrequency; + unsigned short mAmplitude; + short mPhase; + unsigned short mLength; + const unsigned short mBitrate; + const unsigned short mSamplerate; + std::string mFilename; +}; + +#endif /* SINEGENERATORPARAMETERS_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/Util.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/Util.h new file mode 100644 index 0000000..6c98299 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/Util.h @@ -0,0 +1,62 @@ +/* + * Util.h + * + * Created on: 31.03.2011 + * Author: sven + */ + +#ifndef UTIL_H_ +#define UTIL_H_ + +#ifndef _GLIBCXX_SSTREAM + #include +#endif +#ifndef _GLIBMM_USTRING_H + #include +#endif + +class Util +{ +public: + static Glib::ustring ToUString(unsigned short val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static Glib::ustring ToUString(double val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static Glib::ustring ToUString(short val) + { + std::ostringstream ssIn; + ssIn << val; + Glib::ustring res = ssIn.str(); + return res; + } + + static unsigned short ToUShort(Glib::ustring& val) + { + std::istringstream buffer(val.raw()); + unsigned short res; + buffer >> res; + return res; + } + + static short ToShort(Glib::ustring& val) + { + std::istringstream buffer(val.raw()); + short res; + buffer >> res; + return res; + } +}; + +#endif /* UTIL_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/main.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/main.cpp new file mode 100644 index 0000000..3a1b94f --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/src/main.cpp @@ -0,0 +1,23 @@ +/* + * main.cpp + * + * Created on: 31.03.2011 + * Author: sven + */ +#ifndef MAINCONTROLLER_H_ + #include "MainController.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + + +int main(int argc, char* argv[]) +{ + Gtk::Main kit(argc,argv); + MainController mainController; + mainController.startApp(kit); + + return 0; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/ui/sinegen.glade b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/ui/sinegen.glade new file mode 100644 index 0000000..353fc6a --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/SineGenerator/ui/sinegen.glade @@ -0,0 +1,321 @@ + + + + + + 4 + SineGenerator + 440 + 250 + + + True + 5 + 8 + + + True + 0 + Frequency (Hz) + + + + + True + 0 + Amplitude (% of max.) + + + 1 + 2 + + + + + True + 0 + Phase (degree) + + + 2 + 3 + + + + + True + 0 + File + + + 4 + 5 + + + + + True + 0 + Bitrate + + + 4 + 5 + 1 + 2 + + + + + True + 0 + Samplerate (Hz) + + + 4 + 5 + 2 + 3 + + + + + True + True + + 1 + True + if-valid + + + 2 + 3 + + + + + True + True + + 1 + True + if-valid + + + 2 + 3 + 1 + 2 + + + + + True + True + + 1 + True + if-valid + + + 2 + 3 + 2 + 3 + + + + + True + True + + + + 6 + 7 + + + + + True + True + False + + + + 6 + 7 + 1 + 2 + + + + + True + True + False + + + + 6 + 7 + 2 + 3 + + + + + Start + True + True + True + + + 6 + 7 + 4 + 5 + + + + + True + + + 3 + 4 + + + + + True + + + 3 + 4 + 1 + 2 + + + + + True + + + 3 + 4 + 2 + 3 + + + + + True + 0 + Length (sec) + + + 3 + 4 + + + + + True + True + + 1 + True + if-valid + + + 2 + 3 + 3 + 4 + + + + + True + + + 3 + 4 + 3 + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + 1 + 10 + 10 + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.cproject b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.cproject new file mode 100644 index 0000000..b6afac2 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.cproject @@ -0,0 +1,946 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.project b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.project new file mode 100644 index 0000000..d9be8c9 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/.project @@ -0,0 +1,82 @@ + + + Superposition + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/Superposition/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.cpp new file mode 100644 index 0000000..5392621 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.cpp @@ -0,0 +1,104 @@ +/* + * SuperpositionController.cpp + * + * Created on: 01.04.2011 + * Author: sven + */ +#ifndef SUPERPOSITIONCONTROLLER_H_ + #include "SuperpositionController.h" +#endif + +#ifndef _GLIBCXX_IOSTREAM + #include +#endif + +#ifndef WAVEFILESUPERPOSITION_H_ + #include "WavefileSuperposition.h" +#endif + +const char* SuperpositionController::UI_FILENAME = "ui/superpos.glade"; + +SuperpositionController::SuperpositionController() +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("mainwindow",mPtrMainWin); + builder->get_widget("sourcefile1",mPtrSrcFile1); + builder->get_widget("sourcefile2",mPtrSrcFile2); + builder->get_widget("destinationfile",mPtrDstFile); + builder->get_widget("src1btn",mPtrOpenBtnSrc1); + builder->get_widget("src2btn",mPtrOpenBtnSrc2); + builder->get_widget("dstbtn",mPtrOpenBtnDst); + builder->get_widget("startbtn",mPtrStartBtn); + + mPtrMainWin->signal_hide().connect(sigc::ptr_fun(&Gtk::Main::quit)); + mPtrOpenBtnSrc1->signal_clicked().connect(sigc::mem_fun(this,&SuperpositionController::on_button_src1)); + mPtrOpenBtnSrc2->signal_clicked().connect(sigc::mem_fun(this,&SuperpositionController::on_button_src2)); + mPtrOpenBtnDst->signal_clicked().connect(sigc::mem_fun(this,&SuperpositionController::on_button_dst)); + mPtrStartBtn->signal_clicked().connect(sigc::mem_fun(this,&SuperpositionController::on_button_start)); +} + +SuperpositionController::~SuperpositionController() { +} + +void SuperpositionController::startApp(Gtk::Main& kit) +{ + kit.run(*mPtrMainWin); +} + +void SuperpositionController::on_button_src1() +{ + std::string filename; + choose_file(filename); + mParams.setSourceFileOne(filename); + mPtrSrcFile1->set_text(mParams.getSourceFileOne()); +} + +void SuperpositionController::on_button_src2() +{ + std::string filename; + choose_file(filename); + mParams.setSourceFileTwo(filename); + mPtrSrcFile2->set_text(mParams.getSourceFileTwo()); +} + +void SuperpositionController::on_button_dst() +{ + std::string filename; + choose_file(filename); + mParams.setDestinationFile(filename); + mPtrDstFile->set_text(mParams.getDestinationFile()); +} + +void SuperpositionController::choose_file(std::string& filename) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + Gtk::FileChooserDialog* ptrFilechooser; + builder->get_widget("filechooserdlg",ptrFilechooser); + Gtk::FileFilter waveFilter; + waveFilter.set_name("Wave files"); + waveFilter.add_pattern("*.wav"); + ptrFilechooser->add_filter(waveFilter); + ptrFilechooser->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + ptrFilechooser->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + ptrFilechooser->set_transient_for(*mPtrMainWin); + int result = ptrFilechooser->run(); + switch (result) + { + case Gtk::RESPONSE_OK: + filename = ptrFilechooser->get_filename(); + break; + default: + break; + } + delete ptrFilechooser; +} + +void SuperpositionController::on_button_start() +{ + if(!mParams.validate()) + { + std::cout << "Please specify 3 different files" << std::endl; + return; + } + WavefileSuperposition superPos(mParams); +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.h new file mode 100644 index 0000000..fe0637b --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionController.h @@ -0,0 +1,48 @@ +/* + * SuperpositionController.h + * + * Created on: 01.04.2011 + * Author: sven + */ + +#ifndef SUPERPOSITIONCONTROLLER_H_ +#define SUPERPOSITIONCONTROLLER_H_ + +#ifndef SUPERPOSITIONPARAMETERS_H_ + #include "SuperpositionParameters.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +#ifndef _GLIBCXX_STRING + #include +#endif + +class SuperpositionController { +public: + SuperpositionController(); + virtual ~SuperpositionController(); + void startApp(Gtk::Main&); +private: + static const char* UI_FILENAME; + SuperpositionParameters mParams; + + Gtk::Window* mPtrMainWin; + Gtk::Entry* mPtrSrcFile1; + Gtk::Entry* mPtrSrcFile2; + Gtk::Entry* mPtrDstFile; + Gtk::Button* mPtrOpenBtnSrc1; + Gtk::Button* mPtrOpenBtnSrc2; + Gtk::Button* mPtrOpenBtnDst; + Gtk::Button* mPtrStartBtn; + + void on_button_src1(); + void on_button_src2(); + void on_button_dst(); + void on_button_start(); + void choose_file(std::string&); +}; + +#endif /* SUPERPOSITIONCONTROLLER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionParameters.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionParameters.h new file mode 100644 index 0000000..4f87444 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/SuperpositionParameters.h @@ -0,0 +1,65 @@ +/* + * SuperpositionParameters.h + * + * Created on: 01.04.2011 + * Author: sven + */ + +#ifndef SUPERPOSITIONPARAMETERS_H_ +#define SUPERPOSITIONPARAMETERS_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +class SuperpositionParameters +{ +public: +private: + std::string mSourceFileOne; + std::string mSourceFileTwo; + std::string mDestinationFile; +public: + bool validate() const + { + return !(mSourceFileOne.empty() + || mSourceFileTwo.empty() + || mDestinationFile.empty() + || (mSourceFileOne.compare(mSourceFileTwo) == 0) + || (mSourceFileOne.compare(mDestinationFile) == 0) + || (mSourceFileTwo.compare(mDestinationFile) == 0) + ); + } + std::string getDestinationFile() const + { + return mDestinationFile; + } + + std::string getSourceFileOne() const + { + return mSourceFileOne; + } + + std::string getSourceFileTwo() const + { + return mSourceFileTwo; + } + + void setDestinationFile(std::string& mDestinationFile) + { + this->mDestinationFile = mDestinationFile; + } + + void setSourceFileOne(std::string& mSourceFileOne) + { + this->mSourceFileOne = mSourceFileOne; + } + + void setSourceFileTwo(std::string& mSourceFileTwo) + { + this->mSourceFileTwo = mSourceFileTwo; + } + +}; + +#endif /* SUPERPOSITIONPARAMETERS_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.cpp new file mode 100644 index 0000000..91e16a2 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.cpp @@ -0,0 +1,77 @@ +/* + * WavefileSuperposition.cpp + * + * Created on: 01.04.2011 + * Author: sven + */ + +#ifndef WAVEFILESUPERPOSITION_H_ + #include "WavefileSuperposition.h" +#endif +#ifndef _GLIBCXX_IOSTREAM + #include +#endif + +#ifndef _GLIBCXX_FSTREAM + #include +#endif + +#ifndef _GLIBCXX_NUMERIC_LIMITS + #include +#endif + +WavefileSuperposition::WavefileSuperposition(SuperpositionParameters& params) +{ + std::cout << "superposing " << params.getSourceFileOne() << " and " << params.getSourceFileTwo() + << " to " << params.getDestinationFile() << std::endl; + std::ofstream supFile; + std::ifstream srcFile1; + std::ifstream srcFile2; + srcFile1.open(params.getSourceFileOne().c_str(), std::ios::in | std::ios::binary); + srcFile2.open(params.getSourceFileTwo().c_str(), std::ios::in | std::ios::binary); + supFile.open(params.getDestinationFile().c_str(), std::ios::out | std::ios::binary); + int dataStartOffset = 0x28; + char header[dataStartOffset]; + srcFile1.read(&header[0],dataStartOffset); + supFile.write(&header[0],dataStartOffset); + int numSamples; + srcFile1.read((char*) &numSamples,sizeof(numSamples)); + std::cout<<"Processing "<< numSamples << " samples" << std::endl; + srcFile2.seekg(srcFile1.tellg()); + supFile.write((char*) &numSamples,sizeof(numSamples)); + if (!(srcFile1.tellg() == srcFile2.tellg()) || !(srcFile1.tellg() == supFile.tellp()) ) { + std::cout << "file positions not in sync" << std::endl; + return; + } + short data1; + short data2; + int result; + short shortResult; + for (int i=0;i std::numeric_limits::max()) + { + shortResult = std::numeric_limits::max(); + } + else if (result < std::numeric_limits::min()) + { + shortResult = std::numeric_limits::min(); + } else + { + shortResult = static_cast(result); + } + supFile.write((char*) &shortResult,sizeof(shortResult)); + i += sizeof(short); + } + supFile.close(); + srcFile1.close(); + srcFile2.close(); + std::cout<<"done" << std::endl; +} + +WavefileSuperposition::~WavefileSuperposition() { + // TODO Auto-generated destructor stub +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.h new file mode 100644 index 0000000..da7ab5e --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/WavefileSuperposition.h @@ -0,0 +1,21 @@ +/* + * WavefileSuperposition.h + * + * Created on: 01.04.2011 + * Author: sven + */ + +#ifndef WAVEFILESUPERPOSITION_H_ +#define WAVEFILESUPERPOSITION_H_ + +#ifndef SUPERPOSITIONPARAMETERS_H_ + #include "SuperpositionParameters.h" +#endif + +class WavefileSuperposition { +public: + WavefileSuperposition(SuperpositionParameters&); + virtual ~WavefileSuperposition(); +}; + +#endif /* WAVEFILESUPERPOSITION_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/main.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/main.cpp new file mode 100644 index 0000000..664127f --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/src/main.cpp @@ -0,0 +1,21 @@ +/* + * main.cpp + * + * Created on: 01.04.2011 + * Author: sven + */ +#ifndef SUPERPOSITIONCONTROLLER_H_ + #include "SuperpositionController.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +int main(int argc,char* argv[]) +{ + Gtk::Main kit(argc,argv); + SuperpositionController superPosController; + superPosController.startApp(kit); + return 0; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/ui/superpos.glade b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/ui/superpos.glade new file mode 100644 index 0000000..fd9fd4e --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Superposition/ui/superpos.glade @@ -0,0 +1,343 @@ + + + + + + 600 + Wavefile Superposition + + + True + 9 + 7 + + + True + 0 + Source File 1 + + + 1 + 2 + 1 + 2 + + + + + True + 0 + Source File 2 + + + 1 + 2 + 3 + 4 + + + + + True + 0 + Destination File + + + 1 + 2 + 5 + 6 + + + + + 400 + True + True + False + + + + 3 + 4 + 1 + 2 + + + + + True + True + False + + + + 3 + 4 + 3 + 4 + + + + + True + True + False + + + + 3 + 4 + 5 + 6 + + + + + ... + True + True + True + + + 5 + 6 + 1 + 2 + + + + + ... + True + True + True + + + 5 + 6 + 3 + 4 + + + + + ... + True + True + True + + + 5 + 6 + 5 + 6 + + + + + Start + True + True + True + + + 5 + 6 + 7 + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + normal + + + True + 2 + + + + + + True + end + + + + + + + + + False + end + 0 + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 1.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 1.wav new file mode 100644 index 0000000..c6df75f Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 1.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 2.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 2.wav new file mode 100644 index 0000000..79902f4 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz 2.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz superponiert.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz superponiert.wav new file mode 100644 index 0000000..bdce2a6 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 3 kHz superponiert.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 1.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 1.wav new file mode 100644 index 0000000..753dece Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 1.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 2.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 2.wav new file mode 100644 index 0000000..5549231 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz 2.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz elim.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz elim.wav new file mode 100644 index 0000000..2a7db88 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz elim.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz superponiert.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz superponiert.wav new file mode 100644 index 0000000..d72ec4b Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei 400 Hz superponiert.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 1bit quant.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 1bit quant.wav new file mode 100644 index 0000000..07ff3de Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 1bit quant.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 4bit quant.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 4bit quant.wav new file mode 100644 index 0000000..e2dce9e Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 4bit quant.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8bit quant.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8bit quant.wav new file mode 100644 index 0000000..5aa4ff2 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8bit quant.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8kHz.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8kHz.wav new file mode 100644 index 0000000..0808499 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache 8kHz.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache.wav new file mode 100644 index 0000000..2c7dcb7 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Testdatei Sprache.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.cproject b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.cproject new file mode 100644 index 0000000..27e4fc4 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.cproject @@ -0,0 +1,945 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.project b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.project new file mode 100644 index 0000000..961da59 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.project @@ -0,0 +1,82 @@ + + + WaveAnalyzer + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/SNRAnalyzer/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.settings/org.eclipse.ltk.core.refactoring.prefs b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 0000000..cf15ba7 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,3 @@ +#Sat Apr 02 20:51:20 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/Util.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/Util.h new file mode 100644 index 0000000..a906e55 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/Util.h @@ -0,0 +1,32 @@ +/* + * Util.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef UTIL_H_ +#define UTIL_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +#ifndef _GLIBCXX_SSTREAM + #include +#endif + +class Util +{ +public: + static std::string ToString(const long double& val) + { + std::ostringstream ssIn; + ssIn.precision(12); + ssIn << val; + std::string res = ssIn.str(); + return res; + } +}; + +#endif /* UTIL_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.cpp new file mode 100644 index 0000000..abe296f --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.cpp @@ -0,0 +1,158 @@ +/* + * WaveAnalyzer.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ +#ifndef WAVEANALYZER_H_ + #include "WaveAnalyzer.h" +#endif + +#ifndef _GLIBCXX_FSTREAM + #include +#endif + +#ifndef _GLIBCXX_IOSTREAM + #include +#endif + +#ifndef _GLIBCXX_CMATH + #include +#endif + +#ifndef _GLIBCXX_MAP + #include +#endif + +#ifndef _GLIBCXX_NUMERIC_LIMITS + #include +#endif + +WaveAnalyzer::WaveAnalyzer() { + // TODO Auto-generated constructor stub + +} + +WaveAnalyzer::~WaveAnalyzer() { + // TODO Auto-generated destructor stub +} + +long double WaveAnalyzer::calcSNR(std::string& fullQuantFilename, std::string& lowQuantFilename) +{ + long double result = 0.0; + double sumXnSquare = 0.0; + double sumDiffSquare = 0.0; + std::ifstream fullQuantFile; + std::ifstream lowQuantFile; + fullQuantFile.open(fullQuantFilename.c_str(), std::ios::in|std::ios::binary); + lowQuantFile.open(lowQuantFilename.c_str(), std::ios::in|std::ios::binary); + int dataLenOffset = 0x28; + fullQuantFile.seekg(dataLenOffset,std::ios_base::cur); + int numSamples = 0; + fullQuantFile.read((char*) &numSamples, sizeof(numSamples)); + lowQuantFile.seekg(dataLenOffset+sizeof(numSamples),std::ios_base::cur); + double fullVal = 0.0; + double lowVal = 0.0; + short data = 0; + int diff = 0; + for(int i=0; i < numSamples; ) { + fullQuantFile.read((char*) &data, sizeof(data)); + fullVal = (double)(data); + //std::cout << "full: " << data << " "<< fullVal << std::endl; + lowQuantFile.read((char*) &data, sizeof(data)); + lowVal = (double)(data); + //std::cout << "low: " << data << " "<< lowVal << std::endl; + sumXnSquare += (fullVal * fullVal); + //std::cout << "Sum Xn Square: " << sumXnSquare << std::endl; + diff = lowVal - fullVal; + sumDiffSquare += (diff * diff); + //std::cout << "Sum Diff Square: " << sumDiffSquare << std::endl; + i += sizeof(data); + } + if (sumDiffSquare != 0.0) { + result = 10.0 * std::log10(sumXnSquare / sumDiffSquare); + } else { + result = std::numeric_limits::infinity(); + } + fullQuantFile.close(); + lowQuantFile.close(); + return result; +} + +long double WaveAnalyzer::calcArithAvg(std::string& wavefilename) +{ + long double result = 0.0; + int sum = 0; + std::ifstream waveFile; + waveFile.open(wavefilename.c_str(), std::ios::in|std::ios::binary); + int dataLenOffset = 0x28; + waveFile.seekg(dataLenOffset,std::ios_base::cur); + int numSamples = 0; + waveFile.read((char*) &numSamples, sizeof(numSamples)); + short data = 0; + for(int i=0 ; i < numSamples; ) { + waveFile.read((char*) &data, sizeof(data)); + sum += data; + i+=sizeof(data); + } + result = ((long double) sum)/((long double)numSamples); + waveFile.close(); + return result; +} + +long double WaveAnalyzer::calcVariance(std::string& wavefilename) +{ + long double variance = 0.0; + std::map statMap; + std::ifstream waveFile; + waveFile.open(wavefilename.c_str(), std::ios::in|std::ios::binary); + UInt32 dataLenOffset = 0x28; + waveFile.seekg(dataLenOffset,std::ios_base::cur); + UInt32 numBytes = 0; + waveFile.read((char*) &numBytes, sizeof(numBytes)); + UInt32 numSamples = numBytes / sizeof(short); + for(UInt32 i=0 ; i < numSamples; i++) { + short data = 0; + waveFile.read((char*) &data, sizeof(data)); + std::map::iterator findIt = statMap.find(data); + if (findIt == statMap.end()) { + statVal* vPtr = new statVal; + vPtr->count = 1UL; + vPtr->p = 0.0; + statMap.insert(std::make_pair(data,vPtr)); + } else { + findIt->second->count++; + } + } + waveFile.close(); + long double expectation = 0.0; + std::map::iterator it; + long double pSum = 0.0; + for(it = statMap.begin() ; it != statMap.end(); it++) + { + long double x = (long double) it->first; + it->second->p = (long double) it->second->count / (long double) numSamples; + long double actExp = (x * it->second->p); + expectation += actExp; + pSum += it->second->p; + } + std::cout << "expectation: " << expectation << " pSum: " << pSum << std::endl; + for(it = statMap.begin() ; it != statMap.end(); it++) + { + long double x = (long double) it->first; + long double diff = x - expectation; + long double diffQuad = (diff*diff); + variance += diffQuad * it->second->p; + } + for (it = statMap.begin() ; it != statMap.end();) { + delete it->second; + it++; + } + statMap.clear(); + return variance; +} + +long double WaveAnalyzer::calcStdDeviation(std::string& wavefilename) +{ + return std::sqrt(calcVariance(wavefilename)); +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.h new file mode 100644 index 0000000..11b5b1f --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzer.h @@ -0,0 +1,33 @@ +/* + * WaveAnalyzer.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef WAVEANALYZER_H_ +#define WAVEANALYZER_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +typedef unsigned long UInt32; + +struct statVal +{ + UInt32 count; + long double p; +}; + +class WaveAnalyzer { +public: + WaveAnalyzer(); + virtual ~WaveAnalyzer(); + long double calcSNR(std::string&, std::string&); + long double calcArithAvg(std::string&); + long double calcVariance(std::string&); + long double calcStdDeviation(std::string&); +}; + +#endif /* WAVEANALYZER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.cpp new file mode 100644 index 0000000..da87dbb --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.cpp @@ -0,0 +1,128 @@ +/* + * WaveAnalyzerController.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ +#ifndef WAVEANALYZERCONTROLLER_H_ + #include "WaveAnalyzerController.h" +#endif +#ifndef WAVEANALYZER_H_ + #include "WaveAnalyzer.h" +#endif +#ifndef UTIL_H_ + #include "Util.h" +#endif + +const char* WaveAnalyzerController::UI_FILENAME = "ui/waveanalyzer.glade"; + +WaveAnalyzerController::WaveAnalyzerController() +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("mainwindow",mPtrMainWin); + + builder->get_widget("fullquantfile",mPtrFullQuantFile); + builder->get_widget("lowquantfile",mPtrLowQuantFile); + builder->get_widget("snrvalue",mPtrSNRValue); + builder->get_widget("avgvalue",mPtrArithAvgValue); + builder->get_widget("variancevalue",mPtrVarianceValue); + builder->get_widget("deviationvalue",mPtrStdDevValue); + + builder->get_widget("openfullquantbtn",mPtrOpenFullQuantBtn); + builder->get_widget("openlowquantbtn",mPtrOpenLowQuantBtn); + builder->get_widget("calcsnrbtn",mPtrCalcSNRBtn); + builder->get_widget("calc_avg_btn",mPtrCalcArithAvgBtn); + builder->get_widget("calc_variance_btn",mPtrCalcVarianceBtn); + builder->get_widget("calc_deviation_btn",mPtrCalcStdDevBtn); + + mPtrOpenFullQuantBtn->signal_clicked().connect(sigc::mem_fun(this,&WaveAnalyzerController::on_open_fullquant_btn)); + mPtrOpenLowQuantBtn->signal_clicked().connect(sigc::mem_fun(this,&WaveAnalyzerController::on_open_lowquant_btn)); + mPtrCalcSNRBtn->signal_clicked().connect(sigc::mem_fun(this,&WaveAnalyzerController::on_calcsnr_btn)); + mPtrCalcArithAvgBtn->signal_clicked().connect(sigc::mem_fun(this,&WaveAnalyzerController::on_calcarithavg_btn)); + mPtrCalcVarianceBtn->signal_clicked().connect(sigc::mem_fun(this,&WaveAnalyzerController::on_calcvariance_btn)); + mPtrCalcStdDevBtn->signal_clicked().connect(sigc::mem_fun(this,&WaveAnalyzerController::on_calcstddev_btn)); +} + +WaveAnalyzerController::~WaveAnalyzerController() { + // TODO Auto-generated destructor stub +} +void WaveAnalyzerController::startApp(Gtk::Main& kit) +{ + kit.run(*mPtrMainWin); +} + +void WaveAnalyzerController::on_open_fullquant_btn() +{ + choose_file(mFullQuantFilename); + mPtrFullQuantFile->set_text(mFullQuantFilename); +} + +void WaveAnalyzerController::on_open_lowquant_btn() +{ + choose_file(mLowQuantFilename); + mPtrLowQuantFile->set_text(mLowQuantFilename); +} + +void WaveAnalyzerController::on_calcsnr_btn() +{ + if (mFullQuantFilename.empty() || mLowQuantFilename.empty()) { + return; + } + WaveAnalyzer waveAnalyzer; + double snr = waveAnalyzer.calcSNR(mFullQuantFilename,mLowQuantFilename); + mPtrSNRValue->set_text(Util::ToString(snr)); +} + +void WaveAnalyzerController::on_calcarithavg_btn() +{ + if (mFullQuantFilename.empty()) { + return; + } + WaveAnalyzer waveAnalyzer; + double arithAvg = waveAnalyzer.calcArithAvg(mFullQuantFilename); + mPtrArithAvgValue->set_text(Util::ToString(arithAvg)); +} + +void WaveAnalyzerController::on_calcvariance_btn() +{ + if (mFullQuantFilename.empty()) { + return; + } + WaveAnalyzer waveAnalyzer; + double variance = waveAnalyzer.calcVariance(mFullQuantFilename); + mPtrVarianceValue->set_text(Util::ToString(variance)); +} + +void WaveAnalyzerController::on_calcstddev_btn() +{ + if (mFullQuantFilename.empty()) { + return; + } + WaveAnalyzer waveAnalyzer; + double stdDev = waveAnalyzer.calcStdDeviation(mFullQuantFilename); + mPtrStdDevValue->set_text(Util::ToString(stdDev)); +} + +void WaveAnalyzerController::choose_file(std::string& filename) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + Gtk::FileChooserDialog* ptrFilechooser; + builder->get_widget("filechooserdialog",ptrFilechooser); + Gtk::FileFilter waveFilter; + waveFilter.set_name("Wave files"); + waveFilter.add_pattern("*.wav"); + ptrFilechooser->add_filter(waveFilter); + ptrFilechooser->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + ptrFilechooser->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + ptrFilechooser->set_transient_for(*mPtrMainWin); + int result = ptrFilechooser->run(); + switch (result) + { + case Gtk::RESPONSE_OK: + filename = ptrFilechooser->get_filename(); + break; + default: + break; + } + delete ptrFilechooser; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.h new file mode 100644 index 0000000..e6c55a1 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/WaveAnalyzerController.h @@ -0,0 +1,53 @@ +/* + * WaveAnalyzerController.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef WAVEANALYZERCONTROLLER_H_ +#define WAVEANALYZERCONTROLLER_H_ + +#ifndef _GTKMM_H + #include +#endif + +#ifndef _GLIBCXX_STRING + #include +#endif + +class WaveAnalyzerController { +public: + WaveAnalyzerController(); + virtual ~WaveAnalyzerController(); + void startApp(Gtk::Main& kit); +private: + static const char* UI_FILENAME; + std::string mFullQuantFilename; + std::string mLowQuantFilename; + + Gtk::Window* mPtrMainWin; + Gtk::Button* mPtrOpenFullQuantBtn; + Gtk::Button* mPtrOpenLowQuantBtn; + Gtk::Button* mPtrCalcSNRBtn; + Gtk::Button* mPtrCalcArithAvgBtn; + Gtk::Button* mPtrCalcVarianceBtn; + Gtk::Button* mPtrCalcStdDevBtn; + + Gtk::Entry* mPtrFullQuantFile; + Gtk::Entry* mPtrLowQuantFile; + Gtk::Entry* mPtrSNRValue; + Gtk::Entry* mPtrArithAvgValue; + Gtk::Entry* mPtrVarianceValue; + Gtk::Entry* mPtrStdDevValue; + + void on_open_fullquant_btn(); + void on_open_lowquant_btn(); + void on_calcsnr_btn(); + void on_calcarithavg_btn(); + void on_calcvariance_btn(); + void on_calcstddev_btn(); + void choose_file(std::string&); +}; + +#endif /* WAVEANALYZERCONTROLLER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/main.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/main.cpp new file mode 100644 index 0000000..755e724 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/src/main.cpp @@ -0,0 +1,22 @@ +/* + * main.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef WAVEANALYZERCONTROLLER_H_ + #include "WaveAnalyzerController.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +int main(int argc, char* argv[]) +{ + Gtk::Main kit(argc,argv); + WaveAnalyzerController controller; + controller.startApp(kit); + return 0; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/ui/waveanalyzer.glade b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/ui/waveanalyzer.glade new file mode 100644 index 0000000..3d9d862 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/WaveAnalyzer/ui/waveanalyzer.glade @@ -0,0 +1,512 @@ + + + + + + WaveAnalyzer + + + True + 13 + 7 + + + True + 0 + 16 bit quant. File + + + 1 + 2 + 1 + 2 + + + + + True + 0 + lower quant. File + + + 1 + 2 + 7 + 8 + + + + + True + 0 + SNR + + + 1 + 2 + 9 + 10 + + + + + 480 + True + True + False + + + + 3 + 4 + 1 + 2 + + + + + True + True + False + + + + 3 + 4 + 7 + 8 + + + + + True + True + False + + + + 3 + 4 + 9 + 10 + + + + + ... + True + True + True + + + 5 + 6 + 1 + 2 + + + + + ... + True + True + True + + + 5 + 6 + 7 + 8 + + + + + Calc SNR + True + True + True + + + 5 + 6 + 9 + 10 + + + + + True + 0 + arith. average + + + 1 + 2 + 3 + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + 0 + variance + + + 1 + 2 + 4 + 5 + + + + + True + 0 + std. deviation + + + 1 + 2 + 5 + 6 + + + + + True + True + False + + + + 3 + 4 + 3 + 4 + + + + + True + True + False + + + + 3 + 4 + 4 + 5 + + + + + True + True + False + + + + 3 + 4 + 5 + 6 + + + + + Calc arith. avg. + True + True + True + + + 5 + 6 + 3 + 4 + + + + + Calc variance + True + True + True + + + 5 + 6 + 4 + 5 + + + + + Calc std. dev. + True + True + True + + + 5 + 6 + 5 + 6 + + + + + + + 5 + Open Wave file + normal + + + True + 2 + + + + + + True + end + + + + + + + + + False + end + 0 + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/fftfile b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/fftfile new file mode 100644 index 0000000..c06971d --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/fftfile @@ -0,0 +1,517 @@ +# Created by Octave 3.2.4, Fri Apr 08 12:59:01 2011 CEST +# name: fftx +# type: complex matrix +# rows: 512 +# columns: 1 + (0,0) + (5.145175712251377,-6.269414745147931) + (12.5291877851386,-2.492210403686213) + (10.45837578187756,5.590118319371623) + (2.06259194403264,4.979537444925082) + (1.263888171839084,-4.166480928056172) + (11.26317987711197,-7.525816188928733) + (17.9647068997405,1.769369193455572) + (10.434055765287,10.434055765287) + (0.2416820538596853,2.453839072464659) + (10.07787863373637,-15.08261123869326) + (44.56756064417943,-13.51942171788094) + (89.7249203619201,37.16527889675317) + (-89.84292172652795,-168.0842842810278) + (-2.469807578412,12.41656117690236) + (-20.3971347411866,16.73949587576628) + (-22.66170385272558,0) + (-9.975168550178612,-8.186409264072667) + (-0.4967334568631717,-2.497247724748416) + (-2.357014395095777,4.409663777917567) + (-7.562145929225459,3.132343404529677) + (-6.916455625848687,-2.098083876418544) + (-2.019249286352282,-3.022020118213001) + (-0.05513730018635103,0.5598184035047616) + (-2.543813630734268,2.543813630734268) + (-4.506136098003216,0.4438156680107128) + (-2.834092049449049,-1.89367976533878) + (-0.3132512913321471,-1.032651115901518) + (-0.4964685464805054,1.198581098204891) + (-2.416548288110905,1.291671970558105) + (-2.75121559068419,-0.547250806314816) + (-1.06378342789516,-1.296223857352315) + (0,-8.893859344775624e-17) + (-0.9180768711848079,1.118679904299468) + (-2.047901385481032,0.407352912746114) + (-1.549513647313266,-0.8282322997966695) + (-0.2736969046424151,-0.6607627791672576) + (-0.1480761231576887,0.4881415593432393) + (-1.144518406060172,0.7647427496348524) + (-1.548887763946034,-0.1525521295137853) + (-0.7395818834172719,-0.7395818834172719) + (-0.01346548741550172,-0.1367173880817897) + (-0.4105939778652681,0.6144973133889069) + (-1.157947393237543,0.3512595015303762) + (-1.027454063823069,-0.4255854079508669) + (-0.2549823699356273,-0.4770384614757576) + (-0.04168446569624672,0.2095619606029062) + (-0.6254180217114674,0.5132673058206202) + (-1.001383987612148,-1.1424780392566e-17) + (-0.5731280198417213,-0.4703540103137287) + (-0.03500168675178619,-0.1759653620982725) + (-0.1961382995702406,0.366948949008048) + (-0.7237809057578722,0.2997998673515948) + (-0.7466729642177261,-0.2265007674347097) + (-0.2422160632126992,-0.362501956014273) + (-0.007262019492188193,0.07373252126232363) + (-0.3643349035331705,0.3643349035331709) + (-0.6962264991753655,0.06857232495822778) + (-0.4692127692061644,-0.3135179490225175) + (-0.05525452163777557,-0.1821497468859687) + (-0.09284044311365948,0.2241366569017249) + (-0.4770209850941344,0.2549730286150316) + (-0.5710938740868648,-0.1135976344906384) + (-0.2313994113983797,-0.2819609986079077) + (0,-0.0006103701895191303) + (-0.2177125039061602,0.2652834535742427) + (-0.5048377587985965,0.1004184737452698) + (-0.3962785206716488,-0.2118152822371022) + (-0.07247707321496322,-0.1749751331166704) + (-0.04053001600668862,0.1336095569752493) + (-0.3233296075173926,0.2160419367499531) + (-0.4506024071673765,-0.04438046343803068) + (-0.2214073398926773,-0.2214073398926773) + (-0.004142460324117631,-0.04205910549467629) + (-0.1296448295813308,0.1940271990512049) + (-0.3748480263945475,0.1137089056635438) + (-0.3406470323218091,-0.1411006207698392) + (-0.08649893670710466,-0.1618281283386953) + (-0.01445584300793527,0.07267443044576358) + (-0.2215354475464197,0.1818094432180807) + (-0.3620219412161122,1.077696959450591e-16) + (-0.2113127743562347,-0.1734199121453244) + (-0.01315225668862606,-0.06612085946130601) + (-0.07506292210503673,0.1404328498629168) + (-0.2819370596324571,0.1167821538353553) + (-0.2958705179647663,-0.08975134040179834) + (-0.09757905204202465,-0.1460373716015297) + (-0.002972745301236116,0.03018278956241083) + (-0.1514632825312519,0.1514632825312518) + (-0.293702429445267,0.02892716444547319) + (-0.2012202892701651,-0.1344510988062662) + (-0.02401613293578138,-0.07917058017640342) + (-0.04090863374347785,0.09876217840165763) + (-0.2130245550891291,0.1138639969261024) + (-0.2583930333884486,-0.05139756998570728) + (-0.1060555049714537,-0.1292290067157298) + (0,1.852050333005838e-16) + (-0.1021512188725903,0.1244716203393606) + (-0.2397151928923315,0.04768231651508514) + (-0.1903426223498234,-0.101740251292053) + (-0.03520381430572974,-0.08498952594415851) + (-0.01990195553988748,0.06560795490894152) + (-0.1604643483747187,0.1072188497316272) + (-0.225959527812884,-0.02225507099621287) + (-0.112157421003504,-0.112157421003504) + (-0.002119299033067417,-0.02151760418502476) + (-0.0669714701727735,0.1002298881947528) + (-0.195477571010737,0.05929747288572713) + (-0.1792927670633276,-0.07426549575303062) + (-0.04594066833113698,-0.08594894519722272) + (-0.007745902316149099,0.03894128061612638) + (-0.119736833566699,0.09826547978917095) + (-0.197326699217804,0) + (-0.1161284194917113,-0.09530413088930222) + (-0.007284427239490818,-0.03662128873860947) + (-0.0417246956701908,0.0780614151208809) + (-0.1590056096604182,0.06586228001474875) + (-0.1680368379058665,-0.05097341750260959) + (-0.0558304089659913,-0.08355611179047283) + (-0.001713482745973072,0.01739728227607918) + (-0.08794724323475447,0.08794724323475483) + (-0.1718381469224483,0.016924580240687) + (-0.1183432377020851,-0.07907442337473879) + (-0.01423354619381362,-0.0469217135475222) + (-0.02441361773567677,0.05893968704406195) + (-0.1279889750531419,0.06841153244483397) + (-0.1562758360202406,-0.03108519650702114) + (-0.06455976072181158,-0.0786662960506444) + (0,0) + (-0.06297511372951559,0.0767353981037186) + (-0.1486976769562882,0.02957780694723065) + (-0.1187918715240818,-0.06349557819005527) + (-0.02210257414883246,-0.05336033427346897) + (-0.01256936499626377,0.04143564335957403) + (-0.101935227915161,0.06811094174434519) + (-0.1443677785724174,-0.01421898511115459) + (-0.07206591640292345,-0.07206591640292354) + (-0.001369396268008532,-0.01390371363723918) + (-0.04351543092499081,0.06512544468721317) + (-0.1277245629121032,0.03874482257458538) + (-0.1178477157558083,-0.04881412216074527) + (-0.03019093982614804,-0.05648327564297943) + (-0.005135639698495322,0.02581860427357242) + (-0.07982398686127919,0.06550985301643787) + (-0.1322418935059879,0) + (-0.07823055382217597,-0.06420215631664099) + (-0.004933534468434871,-0.02480255266892669) + (-0.02852265954548237,0.05336214276386654) + (-0.1084997212304175,0.04494205604733839) + (-0.1152922901231832,-0.03497353385436357) + (-0.03849397923804621,-0.05761031115558517) + (-0.001187011340238288,0.01205192838946388) + (-0.06120799371566583,0.06120799371566586) + (-0.1201389836604449,0.01183265709862092) + (-0.08311099077230513,-0.05553298861036239) + (-0.01004045606290157,-0.03309894785564295) + (-0.01729713025272566,0.04175896644626437) + (-0.09107381062912134,0.04867996597473918) + (-0.1116786529203331,-0.02221426523815464) + (-0.04633154339889697,-0.05645514897748877) + (0,5.513431518727619e-17) + (-0.04557188492314612,0.05552950244654353) + (-0.1080463870777874,0.02149176264046133) + (-0.08666684067120475,-0.04632439145643064) + (-0.01619023676532187,-0.0390866891768708) + (-0.009243951700457675,0.03047322486117353) + (-0.07527595302494006,0.05029778376028182) + (-0.1069747935024027,-0.01053609753589426) + (-0.05361092430461725,-0.05361092430461732) + (-0.001022592984483848,-0.01038256080863882) + (-0.03261598775031187,0.04881327522214376) + (-0.09607678987303331,0.02914457557962345) + (-0.08892397398651138,-0.03683351604532663) + (-0.02299027540992499,-0.04301178004276422) + (-0.003910828406462015,0.01966106209473332) + (-0.06098705011177884,0.05005077854194191) + (-0.1013863844927223,1.077696959450591e-16) + (-0.06018747520147625,-0.0493945843713775) + (-0.003808951868781873,-0.01914889415353409) + (-0.02209777836869887,0.04134203552072146) + (-0.08435102295548466,0.03493933770820865) + (-0.0899407229234571,-0.02728322002007801) + (-0.03013245666810748,-0.04509640829275814) + (-0.0009323391461716779,0.009466198210120569) + (-0.04823886558801278,0.04823886558801233) + (-0.0950028910040138,0.009356968057972842) + (-0.06594345927982048,-0.0440620108012772) + (-0.007993332812980907,-0.02635048690140989) + (-0.01381716675763851,0.0333575913798581) + (-0.07300252396481108,0.03902066201170445) + (-0.08984656018226951,-0.01787159198677422) + (-0.03744331618296107,-0.04562481277864263) + (0,0.0006103701895185023) + (-0.03686299657049853,0.04491769128488943) + (-0.08778974863038176,0.01746246673173431) + (-0.07066844303195001,-0.03777306976088039) + (-0.01324511938634803,-0.03197654685777285) + (-0.00758637999379745,0.02500894324468237) + (-0.06195944049744381,0.04139997455782402) + (-0.08836438861110031,-0.008703132641105301) + (-0.04441461496603153,-0.04441461496603163) + (-0.0008497263772297305,-0.008627416690860559) + (-0.0271835765663042,0.04068309733898971) + (-0.08031327562469617,0.0243627658103937) + (-0.07455439296541591,-0.03088144070076622) + (-0.01933201407299256,-0.03616765446543094) + (-0.003298175753513443,0.01658104921760837) + (-0.05158328325961493,0.04233330653247259) + (-0.086002756295946,-1.1424780392566e-17) + (-0.05120312046450356,-0.04202131498946311) + (-0.003249759066513301,-0.01633764209497441) + (-0.01890819066582631,0.0353747366407787) + (-0.07238555280945184,0.02998307769355062) + (-0.07740881047451559,-0.02348170593943219) + (-0.02601176400545498,-0.03892935590765884) + (-0.0008073859683116031,0.008197527304839494) + (-0.04192710320922784,0.04192710320922786) + (-0.0831337441175356,0.00818795912447141) + (-0.05691587893357775,-0.03802997446181772) + (-0.006966302461139801,-0.02296482156421804) + (-0.01208699786565824,0.02918059417564858) + (-0.06404978049417259,0.03423532092933831) + (-0.07902477342515885,-0.01571900476363965) + (-0.03298232236949183,-0.04018907608930367) + (0,6.691691081390614e-16) + (-0.03282620305125073,0.03999884414961542) + (-0.0782808592872344,0.0155710310413375) + (-0.06315366293680619,-0.03375633611580806) + (-0.01186527572256088,-0.02864530957070208) + (-0.006812953832571154,0.0224592988838816) + (-0.05578251437634395,0.03727268447569891) + (-0.07975541002308599,-0.00785522225850015) + (-0.04018825061470883,-0.04018825061470876) + (-0.0007707928031845272,-0.007825990664277459) + (-0.02471968326861272,0.03699562043107146) + (-0.07321345507193128,0.02220905879150644) + (-0.0681286353538447,-0.02821980474953196) + (-0.0177078625156669,-0.03312908062087437) + (-0.003028063489031483,0.01522310316307324) + (-0.04746269584880485,0.03895162783866519) + (-0.07928933786499485,0) + (-0.04727627909406475,-0.03879863956179445) + (-0.002999878422616745,-0.01508140726559778) + (-0.01697847816857063,0.03176449848584126) + (-0.06814104722039221,0.02822494591299445) + (-0.07268695549536613,-0.02204934689103427) + (-0.02444660745200689,-0.03658693359029393) + (-0.0007598911488383236,0.007715304310196921) + (-0.03950729945420331,0.03950729945420228) + (-0.07819269479753706,0.007701308242887672) + (-0.05454675973158653,-0.03644697962036236) + (-0.006645007719219971,-0.02190565474525319) + (-0.01154369057685875,0.02786893435048965) + (-0.06128952738078072,0.03275993490218643) + (-0.07578386207508007,-0.01507434741452762) + (-0.03170208342602514,-0.03862910042309509) + (0,0) + (-0.03170208342602514,0.03862910042309509) + (-0.07578386207508007,0.01507434741452762) + (-0.06128952738078072,-0.03275993490218643) + (-0.01154369057685875,-0.02786893435048965) + (-0.006645007719219971,0.02190565474525319) + (-0.05454675973158653,0.03644697962036236) + (-0.07819269479753706,-0.007701308242887672) + (-0.03950729945420331,-0.03950729945420228) + (-0.0007598911488383236,-0.007715304310196921) + (-0.02444660745200689,0.03658693359029393) + (-0.07268695549536613,0.02204934689103427) + (-0.06814104722039221,-0.02822494591299445) + (-0.01697847816857063,-0.03176449848584126) + (-0.002999878422616745,0.01508140726559778) + (-0.04727627909406475,0.03879863956179445) + (-0.07928933786499485,-0) + (-0.04746269584880485,-0.03895162783866519) + (-0.003028063489031483,-0.01522310316307324) + (-0.0177078625156669,0.03312908062087437) + (-0.0681286353538447,0.02821980474953196) + (-0.07321345507193128,-0.02220905879150644) + (-0.02471968326861272,-0.03699562043107146) + (-0.0007707928031845272,0.007825990664277459) + (-0.04018825061470883,0.04018825061470876) + (-0.07975541002308599,0.00785522225850015) + (-0.05578251437634395,-0.03727268447569891) + (-0.006812953832571154,-0.0224592988838816) + (-0.01186527572256088,0.02864530957070208) + (-0.06315366293680619,0.03375633611580806) + (-0.0782808592872344,-0.0155710310413375) + (-0.03282620305125073,-0.03999884414961542) + (0,-6.691691081390614e-16) + (-0.03298232236949183,0.04018907608930367) + (-0.07902477342515885,0.01571900476363965) + (-0.06404978049417259,-0.03423532092933831) + (-0.01208699786565824,-0.02918059417564858) + (-0.006966302461139801,0.02296482156421804) + (-0.05691587893357775,0.03802997446181772) + (-0.0831337441175356,-0.00818795912447141) + (-0.04192710320922784,-0.04192710320922786) + (-0.0008073859683116031,-0.008197527304839494) + (-0.02601176400545498,0.03892935590765884) + (-0.07740881047451559,0.02348170593943219) + (-0.07238555280945184,-0.02998307769355062) + (-0.01890819066582631,-0.0353747366407787) + (-0.003249759066513301,0.01633764209497441) + (-0.05120312046450356,0.04202131498946311) + (-0.086002756295946,1.1424780392566e-17) + (-0.05158328325961493,-0.04233330653247259) + (-0.003298175753513443,-0.01658104921760837) + (-0.01933201407299256,0.03616765446543094) + (-0.07455439296541591,0.03088144070076622) + (-0.08031327562469617,-0.0243627658103937) + (-0.0271835765663042,-0.04068309733898971) + (-0.0008497263772297305,0.008627416690860559) + (-0.04441461496603153,0.04441461496603163) + (-0.08836438861110031,0.008703132641105301) + (-0.06195944049744381,-0.04139997455782402) + (-0.00758637999379745,-0.02500894324468237) + (-0.01324511938634803,0.03197654685777285) + (-0.07066844303195001,0.03777306976088039) + (-0.08778974863038176,-0.01746246673173431) + (-0.03686299657049853,-0.04491769128488943) + (0,-0.0006103701895185023) + (-0.03744331618296107,0.04562481277864263) + (-0.08984656018226951,0.01787159198677422) + (-0.07300252396481108,-0.03902066201170445) + (-0.01381716675763851,-0.0333575913798581) + (-0.007993332812980907,0.02635048690140989) + (-0.06594345927982048,0.0440620108012772) + (-0.0950028910040138,-0.009356968057972842) + (-0.04823886558801278,-0.04823886558801233) + (-0.0009323391461716779,-0.009466198210120569) + (-0.03013245666810748,0.04509640829275814) + (-0.0899407229234571,0.02728322002007801) + (-0.08435102295548466,-0.03493933770820865) + (-0.02209777836869887,-0.04134203552072146) + (-0.003808951868781873,0.01914889415353409) + (-0.06018747520147625,0.0493945843713775) + (-0.1013863844927223,-1.077696959450591e-16) + (-0.06098705011177884,-0.05005077854194191) + (-0.003910828406462015,-0.01966106209473332) + (-0.02299027540992499,0.04301178004276422) + (-0.08892397398651138,0.03683351604532663) + (-0.09607678987303331,-0.02914457557962345) + (-0.03261598775031187,-0.04881327522214376) + (-0.001022592984483848,0.01038256080863882) + (-0.05361092430461725,0.05361092430461732) + (-0.1069747935024027,0.01053609753589426) + (-0.07527595302494006,-0.05029778376028182) + (-0.009243951700457675,-0.03047322486117353) + (-0.01619023676532187,0.0390866891768708) + (-0.08666684067120475,0.04632439145643064) + (-0.1080463870777874,-0.02149176264046133) + (-0.04557188492314612,-0.05552950244654353) + (0,-5.513431518727619e-17) + (-0.04633154339889697,0.05645514897748877) + (-0.1116786529203331,0.02221426523815464) + (-0.09107381062912134,-0.04867996597473918) + (-0.01729713025272566,-0.04175896644626437) + (-0.01004045606290157,0.03309894785564295) + (-0.08311099077230513,0.05553298861036239) + (-0.1201389836604449,-0.01183265709862092) + (-0.06120799371566583,-0.06120799371566586) + (-0.001187011340238288,-0.01205192838946388) + (-0.03849397923804621,0.05761031115558517) + (-0.1152922901231832,0.03497353385436357) + (-0.1084997212304175,-0.04494205604733839) + (-0.02852265954548237,-0.05336214276386654) + (-0.004933534468434871,0.02480255266892669) + (-0.07823055382217597,0.06420215631664099) + (-0.1322418935059879,-0) + (-0.07982398686127919,-0.06550985301643787) + (-0.005135639698495322,-0.02581860427357242) + (-0.03019093982614804,0.05648327564297943) + (-0.1178477157558083,0.04881412216074527) + (-0.1277245629121032,-0.03874482257458538) + (-0.04351543092499081,-0.06512544468721317) + (-0.001369396268008532,0.01390371363723918) + (-0.07206591640292345,0.07206591640292354) + (-0.1443677785724174,0.01421898511115459) + (-0.101935227915161,-0.06811094174434519) + (-0.01256936499626377,-0.04143564335957403) + (-0.02210257414883246,0.05336033427346897) + (-0.1187918715240818,0.06349557819005527) + (-0.1486976769562882,-0.02957780694723065) + (-0.06297511372951559,-0.0767353981037186) + (0,-0) + (-0.06455976072181158,0.0786662960506444) + (-0.1562758360202406,0.03108519650702114) + (-0.1279889750531419,-0.06841153244483397) + (-0.02441361773567677,-0.05893968704406195) + (-0.01423354619381362,0.0469217135475222) + (-0.1183432377020851,0.07907442337473879) + (-0.1718381469224483,-0.016924580240687) + (-0.08794724323475447,-0.08794724323475483) + (-0.001713482745973072,-0.01739728227607918) + (-0.0558304089659913,0.08355611179047283) + (-0.1680368379058665,0.05097341750260959) + (-0.1590056096604182,-0.06586228001474875) + (-0.0417246956701908,-0.0780614151208809) + (-0.007284427239490818,0.03662128873860947) + (-0.1161284194917113,0.09530413088930222) + (-0.197326699217804,-0) + (-0.119736833566699,-0.09826547978917095) + (-0.007745902316149099,-0.03894128061612638) + (-0.04594066833113698,0.08594894519722272) + (-0.1792927670633276,0.07426549575303062) + (-0.195477571010737,-0.05929747288572713) + (-0.0669714701727735,-0.1002298881947528) + (-0.002119299033067417,0.02151760418502476) + (-0.112157421003504,0.112157421003504) + (-0.225959527812884,0.02225507099621287) + (-0.1604643483747187,-0.1072188497316272) + (-0.01990195553988748,-0.06560795490894152) + (-0.03520381430572974,0.08498952594415851) + (-0.1903426223498234,0.101740251292053) + (-0.2397151928923315,-0.04768231651508514) + (-0.1021512188725903,-0.1244716203393606) + (0,-1.852050333005838e-16) + (-0.1060555049714537,0.1292290067157298) + (-0.2583930333884486,0.05139756998570728) + (-0.2130245550891291,-0.1138639969261024) + (-0.04090863374347785,-0.09876217840165763) + (-0.02401613293578138,0.07917058017640342) + (-0.2012202892701651,0.1344510988062662) + (-0.293702429445267,-0.02892716444547319) + (-0.1514632825312519,-0.1514632825312518) + (-0.002972745301236116,-0.03018278956241083) + (-0.09757905204202465,0.1460373716015297) + (-0.2958705179647663,0.08975134040179834) + (-0.2819370596324571,-0.1167821538353553) + (-0.07506292210503673,-0.1404328498629168) + (-0.01315225668862606,0.06612085946130601) + (-0.2113127743562347,0.1734199121453244) + (-0.3620219412161122,-1.077696959450591e-16) + (-0.2215354475464197,-0.1818094432180807) + (-0.01445584300793527,-0.07267443044576358) + (-0.08649893670710466,0.1618281283386953) + (-0.3406470323218091,0.1411006207698392) + (-0.3748480263945475,-0.1137089056635438) + (-0.1296448295813308,-0.1940271990512049) + (-0.004142460324117631,0.04205910549467629) + (-0.2214073398926773,0.2214073398926773) + (-0.4506024071673765,0.04438046343803068) + (-0.3233296075173926,-0.2160419367499531) + (-0.04053001600668862,-0.1336095569752493) + (-0.07247707321496322,0.1749751331166704) + (-0.3962785206716488,0.2118152822371022) + (-0.5048377587985965,-0.1004184737452698) + (-0.2177125039061602,-0.2652834535742427) + (0,0.0006103701895191303) + (-0.2313994113983797,0.2819609986079077) + (-0.5710938740868648,0.1135976344906384) + (-0.4770209850941344,-0.2549730286150316) + (-0.09284044311365948,-0.2241366569017249) + (-0.05525452163777557,0.1821497468859687) + (-0.4692127692061644,0.3135179490225175) + (-0.6962264991753655,-0.06857232495822778) + (-0.3643349035331705,-0.3643349035331709) + (-0.007262019492188193,-0.07373252126232363) + (-0.2422160632126992,0.362501956014273) + (-0.7466729642177261,0.2265007674347097) + (-0.7237809057578722,-0.2997998673515948) + (-0.1961382995702406,-0.366948949008048) + (-0.03500168675178619,0.1759653620982725) + (-0.5731280198417213,0.4703540103137287) + (-1.001383987612148,1.1424780392566e-17) + (-0.6254180217114674,-0.5132673058206202) + (-0.04168446569624672,-0.2095619606029062) + (-0.2549823699356273,0.4770384614757576) + (-1.027454063823069,0.4255854079508669) + (-1.157947393237543,-0.3512595015303762) + (-0.4105939778652681,-0.6144973133889069) + (-0.01346548741550172,0.1367173880817897) + (-0.7395818834172719,0.7395818834172719) + (-1.548887763946034,0.1525521295137853) + (-1.144518406060172,-0.7647427496348524) + (-0.1480761231576887,-0.4881415593432393) + (-0.2736969046424151,0.6607627791672576) + (-1.549513647313266,0.8282322997966695) + (-2.047901385481032,-0.407352912746114) + (-0.9180768711848079,-1.118679904299468) + (0,8.893859344775624e-17) + (-1.06378342789516,1.296223857352315) + (-2.75121559068419,0.547250806314816) + (-2.416548288110905,-1.291671970558105) + (-0.4964685464805054,-1.198581098204891) + (-0.3132512913321471,1.032651115901518) + (-2.834092049449049,1.89367976533878) + (-4.506136098003216,-0.4438156680107128) + (-2.543813630734268,-2.543813630734268) + (-0.05513730018635103,-0.5598184035047616) + (-2.019249286352282,3.022020118213001) + (-6.916455625848687,2.098083876418544) + (-7.562145929225459,-3.132343404529677) + (-2.357014395095777,-4.409663777917567) + (-0.4967334568631717,2.497247724748416) + (-9.975168550178612,8.186409264072667) + (-22.66170385272558,-0) + (-20.3971347411866,-16.73949587576628) + (-2.469807578412,-12.41656117690236) + (-89.84292172652795,168.0842842810278) + (89.7249203619201,-37.16527889675317) + (44.56756064417943,13.51942171788094) + (10.07787863373637,15.08261123869326) + (0.2416820538596853,-2.453839072464659) + (10.434055765287,-10.434055765287) + (17.9647068997405,-1.769369193455572) + (11.26317987711197,7.525816188928733) + (1.263888171839084,4.166480928056172) + (2.06259194403264,-4.979537444925082) + (10.45837578187756,-5.590118319371623) + (12.5291877851386,2.492210403686213) + (5.145175712251377,6.269414745147931) diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/ifftx.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/ifftx.wav new file mode 100644 index 0000000..fa55124 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/ifftx.wav differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/mus-eisenhauer-abgabe1.zip b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/mus-eisenhauer-abgabe1.zip new file mode 100644 index 0000000..ec40b90 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/mus-eisenhauer-abgabe1.zip differ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/wave_fft.m b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/wave_fft.m new file mode 100644 index 0000000..8d12feb --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/wave_fft.m @@ -0,0 +1,53 @@ +wavefile = 'Testdatei 400 Hz 1.wav'; +M = wavread(wavefile); % load data from wave file +x = M(:,1); % wave samples as vector +fs = 16000; % sample frequency +sec = 0.025; % time span +x = x(1:(sec*fs)+1); % samples of time span +wavwrite(x,16000,16,"x.wav") +N = length(x); % number of samples +t = [0:1/fs:sec]; % time vector + +nfft = 2^(nextpow2(N)); % Use next highest power of 2 greater than or equal to length(x) to calculate FFT. +NumUniquePts = ceil((nfft+1)/2); % Calculate the numberof unique points +fftx = fft(x,nfft); % Take fft, padding with zeros so that length(fftx) is equal to nfft +save fftfile fftx; % Write fft complex data to file +p = unwrap(angle(fftx)); % phase + +ifftx = ifft(fftx); +ifftx = ifftx(1:N); +wavwrite(ifftx,16000,16,"ifftx.wav") + +fftx = fftx(1:NumUniquePts); % FFT is symmetric, throw away second half +magX = abs(fftx)/N; % Take the magnitude of fft of x and scale the fft so that it is not a function of the length of x +magX = magX.^2; % Take the square of the magnitude of fft of x. + +% Since we dropped half the FFT, we multiply mx by 2 to keep the same energy. +% The DC component and Nyquist component, if it exists, are unique and should not be multiplied by 2. +if rem(nfft, 2) % odd nfft excludes Nyquist point + magX(2:end) = magX(2:end)*2; +else + magX(2:end -1) = magX(2:end -1)*2; +end +f = (0:NumUniquePts-1)*fs/nfft; % This is an evenly spaced frequency vector with NumUniquePts points. + +figure(1); +subplot(5,1,1); +plot(t,x); +title('time domain') +xlabel('time'); +ylabel('Amplitude'); + +subplot(5,1,3); +plot(f,magX); +xlabel('f/Hz'); +ylabel('Amplitudenspektrum'); +title('frequency domain'); + +subplot(5,1,5); +px = (1:1:length(p)); +plot(px,p); +title('phase'); + +% print -Ppng 'plot.png' + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/x.wav b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/x.wav new file mode 100644 index 0000000..fa55124 Binary files /dev/null and b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/x.wav differ -- cgit v1.2.3