def compare_results(self): """ Function to compare the absorption coefficient using the cepstral technique comparing to the impedance tube. """ self.logger.debug("Entering compare_results") measurement_filename = "../testdata/120519_asphalt_13.db" alpha = self.loadAbsorptionCoefficient(measurement_filename) grapher = Grapher(alpha.measurement_settings) fig = figure() handler = Object() handler.axes = fig.add_subplot(111) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) a = [ 0.032116172, 0.034017778, 0.032430265, 0.02675464, 0.192021209, 0.415370952, 0.372468791, 0.691662969, 0.54285943, 0.338953418, 0.284023669, 0.355485023, 0.475263874, 0.282777409, 0.595041322 ] f = [ 100, 125, 160, 200, 250, 300, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000 ] handler.axes.plot(f, a, "x") show()
def misidentificationAnalysis(self): """ Preform analysis on misidentifying the synchronization impulse """ self.logger.debug("Entering misidentificationAnalysis") measurement_file = "/Users/lance/Programming/Python/Masters/testdata/2012/08/120806_reflective_63.db" alpha = self.loadAbsorptionCoefficient(measurement_file) print alpha.measurement_settings grapher = Grapher(alpha.measurement_settings) fig = figure(figsize=(7, 5)) mic_impulse_loc = int(alpha.measurement_settings["microphone impulse location"]) gen_impulse_loc = int(alpha.measurement_settings["generator impulse location"]) (gen_start, gen_end) = (gen_impulse_loc - 20, gen_impulse_loc + 20) (mic_start, mic_end) = (mic_impulse_loc - 20, mic_impulse_loc + 100) gen_signal = alpha.generator_signals[0][gen_start:gen_end] mic_signal = alpha.microphone_signals[0][mic_start:mic_end] ax = fig.add_subplot(211) ax.plot(gen_signal) ax.axvline(x=gen_impulse_loc - gen_start, color="black", linestyle="--", lw=1) ax = fig.add_subplot(212) ax.plot(mic_signal) ax.axvline(x=mic_impulse_loc - mic_start, color="black", linestyle="--", lw=1) show() fig = figure(figsize=(7, 5)) ax = fig.add_subplot(111) resp = abs(fft(alpha.microphone_signals[0])) ** 2 t = arange(0, len(alpha.generator_cepstrum) / 44100.0, 1 / 44100.0) ax.plot(t, alpha.generator_cepstrum) ax.plot(t, alpha.microphone_cepstrum) ax.plot(t, alpha.power_cepstrum) show() fig = figure(figsize=(7, 5)) handler = Object() handler.figure = fig handler.axes = fig.add_subplot(111) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) show() alpha.measurement_settings["microphone impulse location"] = mic_impulse_loc alpha.measurement_settings["generator impulse location"] = gen_impulse_loc + 3 alpha.determineAlpha() fig = figure(figsize=(7, 5)) ax = fig.add_subplot(111) ax.plot(alpha.generator_cepstrum) ax.plot(alpha.microphone_cepstrum) show() fig = figure(figsize=(7, 5)) handler = Object() handler.figure = fig handler.axes = fig.add_subplot(111) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) show()
def showFilterTests(self): """" plot the absorption coefficient of the various tests done with different filter orders """ self.logger.debug("Entering showFilterTests") hpf_order_tests = [1, 3, 4, 5] hpf_cutoff_tests = [100, 150, 200, 500, 1000] fig = figure() for order_index, hpf_order in enumerate(hpf_order_tests): for cutoff_index, hpf_cutoff in enumerate(hpf_cutoff_tests): measurement_filename = "../test data/120323_hpf_%s_%s.db" % ( hpf_order, hpf_cutoff) alpha = self.loadAbsorptionCoefficient(measurement_filename) grapher = Grapher(alpha.measurement_settings) handler = Object() handler.axes = fig.add_subplot( len(hpf_order_tests), len(hpf_cutoff_tests), order_index * len(hpf_cutoff_tests) + cutoff_index) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) plot(alpha.alpha) title("%s Hz order %s" % (hpf_cutoff, hpf_order)) show()
def compare_results(self): """ Function to compare the absorption coefficient using the cepstral technique comparing to the impedance tube. """ self.logger.debug("Entering compare_results") measurement_filename = "../testdata/120519_asphalt_13.db" alpha = self.loadAbsorptionCoefficient(measurement_filename) grapher = Grapher(alpha.measurement_settings) fig = figure() handler = Object() handler.axes = fig.add_subplot(111) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) a = [0.032116172, 0.034017778, 0.032430265, 0.02675464, 0.192021209, 0.415370952, 0.372468791, 0.691662969, 0.54285943, 0.338953418, 0.284023669, 0.355485023, 0.475263874, 0.282777409, 0.595041322] f = [100, 125, 160, 200, 250, 300, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000] handler.axes.plot(f, a, "x") show()
def showFilterTests(self): """" plot the absorption coefficient of the various tests done with different filter orders """ self.logger.debug("Entering showFilterTests") hpf_order_tests = [1, 3, 4, 5] hpf_cutoff_tests = [100, 150, 200, 500, 1000] fig = figure() for order_index, hpf_order in enumerate(hpf_order_tests): for cutoff_index, hpf_cutoff in enumerate(hpf_cutoff_tests): measurement_filename = "../test data/120323_hpf_%s_%s.db" % (hpf_order, hpf_cutoff) alpha = self.loadAbsorptionCoefficient(measurement_filename) grapher = Grapher(alpha.measurement_settings) handler = Object() handler.axes = fig.add_subplot(len(hpf_order_tests), len(hpf_cutoff_tests), order_index * len(hpf_cutoff_tests) + cutoff_index) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) plot(alpha.alpha) title("%s Hz order %s" % (hpf_cutoff, hpf_order)) show()
class RapidController(QMainWindow, Ui_RapidAlphaWindow): # pyqtSignals startMeasurement = pyqtSignal() saveGraph = pyqtSignal("QString") exportData = pyqtSignal("QString") loadMeasurement = pyqtSignal("QString") saveMeasurement = pyqtSignal("QString") showPreferences = pyqtSignal() savePreferences = pyqtSignal("QString") loadPreferences = pyqtSignal("QString") exit = pyqtSignal() def __init__(self, measurement_settings, audio_devices): """ Constructor for RapidController, sets up the view, signals and shows the window. :param measurement_settings: A dictionary containing the settings to used for the measurement. :type measurement_settings: dict :param audio_devices: A list of all the input / output devices available in the system. :type: array of AudioDevice """ self.logger = logging.getLogger("Alpha") self.logger.debug("Creating RapidController") QMainWindow.__init__(self) self.measurement_settings = measurement_settings self.audio_devices = audio_devices self.grapher = Grapher(self.measurement_settings) self.alpha = None self.setupUi(self) self._setupWidgets() self._setupSignals() self.showMaximized() def update(self): """ Updates the graph showing the absorption coefficient of the material measured. """ self.logger.debug("Entering update") self.grapher.graphAbsorption(self.alpha.alpha, self.AlphaPlot) self.grapher.graphCepstrum( self.alpha.microphone_cepstrum, self.alpha.generator_cepstrum, self.alpha.power_cepstrum, self.alpha.impulse_response, self.alpha.window, float(self.alpha.measurement_settings["window start"]), self.CepstrumPlot) def _setupWidgets(self): """ Setup the widgets to show the user. The graph is formatted with no data. """ self.logger.debug("Entering _setupWidgets") self.grapher.graphAbsorption([], self.AlphaPlot) self.grapher.graphCepstrum([], [], [], [], [], 0, self.CepstrumPlot) # Add Volume slider to toolbar self.gainSlider = QSlider(Qt.Horizontal) self.gainSlider.setMaximumWidth(100) self.gainSlider.setMaximum(0) self.gainSlider.setMinimum(-1000) self.gainSpin = QDoubleSpinBox() self.gainSpin.setMaximum(0) self.gainSpin.setMinimum(-10) self.gainSpin.setSingleStep(0.01) self.toolBar.addSeparator() self.toolBar.addWidget(QSpacerItem(0, 0).widget()) self.toolBar.addWidget(QLabel("Gain: ")) self.toolBar.addWidget(self.gainSlider) self.toolBar.addWidget(self.gainSpin) self.toolBar.addWidget(QLabel(" dB")) self.updateWidgets() def updateWidgets(self): """ Set the values for widgets on the screen. """ gain = 20 * log10(float(self.measurement_settings["gain"])) self.gainSlider.setValue(gain) self.gainSpin.setValue(gain) def _updateMeasurementSettings(self): """ Update the Measurement Settings dictionary. For the Rapid View, the only settings that change are the input and output devices. """ self.logger.debug("Entering _updateMeasurementSettings") selected_index = self.InputDeviceList.currentIndex() input_device = self.InputDeviceList.itemData(selected_index).toInt() self.measurement_settings["input device"] = input_device[0] selected_index = self.OutputDeviceList.currentIndex() output_device = self.OutputDeviceList.itemData(selected_index).toInt() self.measurement_settings["output device"] = output_device[0] def _setupSignals(self): """ Connects the various button signals to the class signals. """ self.logger.debug("Entering _setupSignals") save_func = self._showSaveDialog self.actionSave.triggered.connect(lambda: save_func("measurement")) self.actionExport_Data.triggered.connect(lambda: save_func("csv")) self.actionExport_Graph.triggered.connect(lambda: save_func("graph")) self.actionSave_Preferences.triggered.connect( lambda: save_func("preferences")) load_func = self._showOpenDialog self.actionLoad_Preferences.triggered.connect( lambda: load_func("preferences")) self.actionLoad_Measurement.triggered.connect( lambda: load_func("measurement")) self.actionExit.triggered.connect(self.exit) self.actionStart_Measurement.triggered.connect(self.startMeasurement) self.actionPreferences.triggered.connect(self.showPreferences) self.gainSlider.valueChanged.connect(self._updateWidgets) self.gainSpin.valueChanged.connect(self._updateWidgets) def _updateWidgets(self): """ Keeps widgets synchronized with the measurement settings, and each other """ self.logger.debug("Entering _updateWidgets") # Keep the gain in sync gain = float(self.measurement_settings["gain"]) gain_db = 20 * log10(gain) self.logger.debug("sender: %s" % (self.sender())) if self.sender() == self.gainSlider: self.logger.debug("Slider: %s" % (self.gainSlider.value())) self.gainSpin.setValue((self.gainSlider.value() / 100.0)) elif self.sender() == self.gainSpin: self.gainSlider.setValue(self.gainSpin.value() * 100.0) gain = 10**(self.gainSpin.value() / 20.0) self.measurement_settings["gain"] = gain def _showOpenDialog(self, file_type): """ Shows the open dialog to get the filename to load the required data. :param file_type: The type of data to be saved, could be one of "graph", "csv", "measurement" :type file_type: str """ self.logger.debug("Entering _showOpenDialog") if file_type == "measurement": caption = "Select Measurement File to Load" filter = "AlphaDb (*.adb)" signal = self.loadMeasurement elif file_type == "preferences": caption = "Select Preferences File to Load" filter = "Preferences (*.pdb)" signal = self.loadPreferences else: self.logger.debug("Invalid file_type passed: %s" % (file_type)) return dir = "./" filename = QFileDialog.getOpenFileName(self, caption, dir, filter) # filename is a tuple (filename, selected filter) when file is selected # else a blank string if dialog closed if filename != "": signal.emit(filename) def _showSaveDialog(self, file_type): """ Shows the save dialog to get the filename to save the required data to. :param file_type: The type of data to be saved, could be one of "graph", "csv", "measurement" :type file_type: str """ self.logger.debug("Entering _showSaveDialog") if file_type == "graph": caption = "Select file to save the graph" supported_file_types = self.AlphaPlot.figure.canvas.get_supported_filetypes_grouped( ) # Get available output formats filter = [] for key, value in supported_file_types.items(): filter.append("%s (*.%s)" % (key, " *.".join(value))) filter = ";;".join(filter) signal = self.saveGraph elif file_type == "csv": caption = "Select file to export data to" filter = "CSV (*.csv)" signal = self.exportData elif file_type == "measurement": caption = "Enter file name of measurement" filter = "AlphaDb (*.adb)" signal = self.saveMeasurement elif file_type == "preferences": caption = "Enter file name of preferences" filter = "Preferences (*.pdb)" signal = self.savePreferences else: self.logger.debug("Invalid file_type passed: %s" % (file_type)) return dir = "./" filename = QFileDialog.getSaveFileName(self, caption, dir, filter) if filename != "": signal.emit(filename)
class RapidController(QMainWindow, Ui_RapidAlphaWindow): # pyqtSignals startMeasurement = pyqtSignal() saveGraph = pyqtSignal("QString") exportData = pyqtSignal("QString") loadMeasurement = pyqtSignal("QString") saveMeasurement = pyqtSignal("QString") showPreferences = pyqtSignal() savePreferences = pyqtSignal("QString") loadPreferences = pyqtSignal("QString") exit = pyqtSignal() def __init__(self, measurement_settings, audio_devices): """ Constructor for RapidController, sets up the view, signals and shows the window. :param measurement_settings: A dictionary containing the settings to used for the measurement. :type measurement_settings: dict :param audio_devices: A list of all the input / output devices available in the system. :type: array of AudioDevice """ self.logger = logging.getLogger("Alpha") self.logger.debug("Creating RapidController") QMainWindow.__init__(self) self.measurement_settings = measurement_settings self.audio_devices = audio_devices self.grapher = Grapher(self.measurement_settings) self.alpha = None self.setupUi(self) self._setupWidgets() self._setupSignals() self.showMaximized() def update(self): """ Updates the graph showing the absorption coefficient of the material measured. """ self.logger.debug("Entering update") self.grapher.graphAbsorption(self.alpha.alpha, self.AlphaPlot) self.grapher.graphCepstrum(self.alpha.microphone_cepstrum, self.alpha.generator_cepstrum, self.alpha.power_cepstrum, self.alpha.impulse_response, self.alpha.window, float(self.alpha.measurement_settings["window start"]), self.CepstrumPlot) def _setupWidgets(self): """ Setup the widgets to show the user. The graph is formatted with no data. """ self.logger.debug("Entering _setupWidgets") self.grapher.graphAbsorption([], self.AlphaPlot) self.grapher.graphCepstrum([], [], [], [], [], 0, self.CepstrumPlot) # Add Volume slider to toolbar self.gainSlider = QSlider(Qt.Horizontal) self.gainSlider.setMaximumWidth(100) self.gainSlider.setMaximum(0) self.gainSlider.setMinimum(-1000) self.gainSpin = QDoubleSpinBox() self.gainSpin.setMaximum(0) self.gainSpin.setMinimum(-10) self.gainSpin.setSingleStep(0.01) self.toolBar.addSeparator() self.toolBar.addWidget(QSpacerItem(0,0).widget()) self.toolBar.addWidget(QLabel("Gain: ")) self.toolBar.addWidget(self.gainSlider) self.toolBar.addWidget(self.gainSpin) self.toolBar.addWidget(QLabel(" dB")) self.updateWidgets() def updateWidgets(self): """ Set the values for widgets on the screen. """ gain = 20 * log10(float(self.measurement_settings["gain"]) ) self.gainSlider.setValue(gain) self.gainSpin.setValue(gain) def _updateMeasurementSettings(self): """ Update the Measurement Settings dictionary. For the Rapid View, the only settings that change are the input and output devices. """ self.logger.debug("Entering _updateMeasurementSettings") selected_index = self.InputDeviceList.currentIndex() input_device = self.InputDeviceList.itemData(selected_index).toInt() self.measurement_settings["input device"] = input_device[0] selected_index = self.OutputDeviceList.currentIndex() output_device = self.OutputDeviceList.itemData(selected_index).toInt() self.measurement_settings["output device"] = output_device[0] def _setupSignals(self): """ Connects the various button signals to the class signals. """ self.logger.debug("Entering _setupSignals") save_func = self._showSaveDialog self.actionSave.triggered.connect(lambda: save_func("measurement")) self.actionExport_Data.triggered.connect(lambda: save_func("csv")) self.actionExport_Graph.triggered.connect(lambda: save_func("graph")) self.actionSave_Preferences.triggered.connect(lambda: save_func("preferences")) load_func = self._showOpenDialog self.actionSave_Preferences.triggered.connect(lambda: load_func("preferences")) self.actionLoad_Measurement.triggered.connect(lambda: load_func("measurement")) self.actionExit.triggered.connect(self.exit) self.actionStart_Measurement.triggered.connect(self.startMeasurement) self.actionPreferences.triggered.connect(self.showPreferences) self.gainSlider.valueChanged.connect(self._updateWidgets) self.gainSpin.valueChanged.connect(self._updateWidgets) def _updateWidgets(self): """ Keeps widgets synchronized with the measurement settings, and each other """ self.logger.debug("Entering _updateWidgets") # Keep the gain in sync gain = float(self.measurement_settings["gain"]) gain_db = 20 * log10(gain) self.logger.debug("sender: %s" %(self.sender())) if self.sender() == self.gainSlider: self.logger.debug("Slider: %s" % (self.gainSlider.value())) self.gainSpin.setValue((self.gainSlider.value() / 100.0)) elif self.sender() == self.gainSpin: self.gainSlider.setValue(self.gainSpin.value() * 100.0) gain = 10 ** (self.gainSpin.value() / 20.0) self.measurement_settings["gain"] = gain def _showOpenDialog(self, file_type): """ Shows the open dialog to get the filename to load the required data. :param file_type: The type of data to be saved, could be one of "graph", "csv", "measurement" :type file_type: str """ self.logger.debug("Entering _showOpenDialog") if file_type == "measurement": caption = "Select Measurement File to Load" filter = "AlphaDb (*.db)" signal = self.loadMeasurement elif file_type == "preferences": caption = "Select Preferences File to Load" filter = "Preferences (*.db)" signal = self.loadPreferences else: self.logger.debug("Invalid file_type passed: %s" % (file_type)) return dir = "./" filename = QFileDialog.getOpenFileName(self, caption, dir, filter) # filename is a tuple (filename, selected filter) when file is selected # else a blank string if dialog closed print filename if filename != "": signal.emit(filename) def _showSaveDialog(self, file_type): """ Shows the save dialog to get the filename to save the required data to. :param file_type: The type of data to be saved, could be one of "graph", "csv", "measurement" :type file_type: str """ self.logger.debug("Entering _showSaveDialog") if file_type == "graph": caption = "Select file to save the graph" supported_file_types = self.AlphaPlot.figure.canvas.get_supported_filetypes_grouped() # Get available output formats filter = [] for key, value in supported_file_types.items(): filter.append("%s (*.%s)" % (key, " *.".join(value))) filter = ";;".join(filter) signal = self.saveGraph elif file_type == "csv": caption = "Select file to export data to" filter = "CSV (*.csv)" signal = self.exportData elif file_type == "measurement": caption = "Select file to save the measurement to" filter = "AlphaDb (*.db)" signal = self.saveMeasurement elif file_type == "preferences": caption = "Select Filename to save Preferences" filter = "Preferences (*.db)" signal = self.savePreferences else: self.logger.debug("Invalid file_type passed: %s" % (file_type)) return dir = "./" filename = QFileDialog.getSaveFileName(self, caption, dir, filter) if filename != "": signal.emit(filename)
def misidentificationAnalysis(self): """ Preform analysis on misidentifying the synchronization impulse """ self.logger.debug("Entering misidentificationAnalysis") measurement_file = "/Users/lance/Programming/Python/Masters/testdata/2012/08/120806_reflective_63.db" alpha = self.loadAbsorptionCoefficient(measurement_file) print alpha.measurement_settings grapher = Grapher(alpha.measurement_settings) fig = figure(figsize=(7, 5)) mic_impulse_loc = int( alpha.measurement_settings["microphone impulse location"]) gen_impulse_loc = int( alpha.measurement_settings["generator impulse location"]) (gen_start, gen_end) = (gen_impulse_loc - 20, gen_impulse_loc + 20) (mic_start, mic_end) = (mic_impulse_loc - 20, mic_impulse_loc + 100) gen_signal = alpha.generator_signals[0][gen_start:gen_end] mic_signal = alpha.microphone_signals[0][mic_start:mic_end] ax = fig.add_subplot(211) ax.plot(gen_signal) ax.axvline(x=gen_impulse_loc - gen_start, color="black", linestyle="--", lw=1) ax = fig.add_subplot(212) ax.plot(mic_signal) ax.axvline(x=mic_impulse_loc - mic_start, color="black", linestyle="--", lw=1) show() fig = figure(figsize=(7, 5)) ax = fig.add_subplot(111) resp = abs(fft(alpha.microphone_signals[0]))**2 t = arange(0, len(alpha.generator_cepstrum) / 44100.0, 1 / 44100.0) ax.plot(t, alpha.generator_cepstrum) ax.plot(t, alpha.microphone_cepstrum) ax.plot(t, alpha.power_cepstrum) show() fig = figure(figsize=(7, 5)) handler = Object() handler.figure = fig handler.axes = fig.add_subplot(111) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) show() alpha.measurement_settings[ "microphone impulse location"] = mic_impulse_loc alpha.measurement_settings[ "generator impulse location"] = gen_impulse_loc + 3 alpha.determineAlpha() fig = figure(figsize=(7, 5)) ax = fig.add_subplot(111) ax.plot(alpha.generator_cepstrum) ax.plot(alpha.microphone_cepstrum) show() fig = figure(figsize=(7, 5)) handler = Object() handler.figure = fig handler.axes = fig.add_subplot(111) handler.draw = draw grapher.graphAbsorption(alpha.alpha, handler) show()