// Cramer's Rule
// http://mathworld.wolfram.com/CramersRule.html
txVec3d txMatrix3::SolveLinear3(const txVec3d &right){
	txVec3d rtn;
	double det = Determinant();
	double determinInverse = 1.0/Determinant();

	txMatrix3 xM(
		right.GetX(),mat[0][1],mat[0][2],
		right.GetY(),mat[1][1],mat[1][2],
		right.GetZ(),mat[2][1],mat[2][2]);

	txMatrix3 yM(
		mat[0][0],right.GetX(),mat[0][2],
		mat[1][0],right.GetY(),mat[1][2],
		mat[2][0],right.GetZ(),mat[2][2]);

	txMatrix3 zM(
		mat[0][0],mat[0][1],right.GetX(),
		mat[1][0],mat[1][1],right.GetY(),
		mat[2][0],mat[2][1],right.GetZ());

	rtn.SetX(xM.Determinant()*determinInverse);
	rtn.SetY(yM.Determinant()*determinInverse);
	rtn.SetZ(zM.Determinant()*determinInverse);

	return rtn;
}
Exemple #2
0
void MainWindow::updateAllResponses()
{
    // clear responses
    for (int i = 0; i < defaultFilterCount; ++i) {
        for (int j = 0; j < defaultPlotSampleCount; ++j) {
            m_magnitudes[i][j] = 0.0;
            m_phases[i][j] = 0.0;
        }
    }

    // Update frequency and phase response
    for (size_t i = 0; i < cr_filter_count(m_cornrow); ++i) {
        double *magnitudes = m_magnitudes[i];
        double *phases = m_phases[i];

        cr_filter_response(m_cornrow, i, defaultPlotSampleCount, m_frequencies, magnitudes, phases);

        // Update magnitude plot
        QVector<double> xM(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xM.begin());
        QVector<double> yM(defaultPlotSampleCount); qCopy(magnitudes, magnitudes+defaultPlotSampleCount, yM.begin());
        ui->magnitudePlot->graph(i)->setData(xM, yM);
        ui->magnitudePlot->graph(i)->setVisible(cr_filter_type(m_cornrow, i) != FilterType::None);

        // Update phase plot
        QVector<double> xP(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xP.begin());
        QVector<double> yP(defaultPlotSampleCount); qCopy(phases, phases+defaultPlotSampleCount, yP.begin());
        ui->phasePlot->graph(i)->setData(xP, yP);
        ui->phasePlot->graph(i)->setVisible(cr_filter_type(m_cornrow, i) != FilterType::None);
    }
}
void PreferencesWidget::updateAllResponses()
{
    // clear responses
    for (int i = 0; i < defaultFilterCount; ++i) {
        for (int j = 0; j < defaultPlotSampleCount; ++j) {
            m_magnitudes[i][j] = 0.0;
            m_phases[i][j] = 0.0;
        }
    }

    // Update frequency and phase response
    size_t i = 0;
    for (const Filter& filter : m_filterManager.filters()) {
        double *magnitudes = m_magnitudes[i];
        double *phases = m_phases[i];

        m_filterManager.filterResponse(i, defaultPlotSampleCount, m_frequencies, magnitudes, phases);

        // Update magnitude plot
        QVector<double> xM(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xM.begin());
        QVector<double> yM(defaultPlotSampleCount); qCopy(magnitudes, magnitudes+defaultPlotSampleCount, yM.begin());
        ui->magnitudePlot->graph(i)->setData(xM, yM);
        ui->magnitudePlot->graph(i)->setVisible(filter.type() != FilterType::None);

        // Update phase plot
        QVector<double> xP(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xP.begin());
        QVector<double> yP(defaultPlotSampleCount); qCopy(phases, phases+defaultPlotSampleCount, yP.begin());
        ui->phasePlot->graph(i)->setData(xP, yP);
        ui->phasePlot->graph(i)->setVisible(filter.type() != FilterType::None);
        ++i;
    }
}
Exemple #4
0
void MainWindow::updateCurrentFilter()
{
    size_t index = ui->filterComboBox->currentIndex();

    // Update frequency and phase response
    double *magnitudes = m_magnitudes[index];
    double *phases = m_phases[index];

    cr_filter_response(m_cornrow, index, defaultPlotSampleCount, m_frequencies, magnitudes, phases);

    // Update magnitude plot
    QVector<double> xM(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xM.begin());
    QVector<double> yM(defaultPlotSampleCount); qCopy(magnitudes, magnitudes+defaultPlotSampleCount, yM.begin());
    ui->magnitudePlot->graph(index)->setData(xM, yM);
    ui->magnitudePlot->graph(index)->setVisible(cr_filter_type(m_cornrow,index) != FilterType::None);

    // Update phase plot
    QVector<double> xP(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xP.begin());
    QVector<double> yP(defaultPlotSampleCount); qCopy(phases, phases+defaultPlotSampleCount, yP.begin());
    ui->phasePlot->graph(index)->setData(xP, yP);
    ui->phasePlot->graph(index)->setVisible(cr_filter_type(m_cornrow,index) != FilterType::None);

    // Update cascade frequency and phase responses
    double magnitudeSum[defaultPlotSampleCount];
    double phaseSum[defaultPlotSampleCount];

    for (int j = 0; j < defaultPlotSampleCount; ++j) {
        magnitudeSum[j] = m_magnitudeSumExceptCurrent[j] + m_magnitudes[index][j];
        phaseSum[j] = m_phaseSumExceptCurrent[j] + m_phases[index][j];
    }

    QVector<double> xMS(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xMS.begin());
    QVector<double> yMS(defaultPlotSampleCount); qCopy(magnitudeSum, magnitudeSum+defaultPlotSampleCount, yMS.begin());
    m_magnitudeSumGraph->setData(xMS, yMS);

    QVector<double> xPS(defaultPlotSampleCount); qCopy(m_frequencies, m_frequencies+defaultPlotSampleCount, xPS.begin());
    QVector<double> yPS(defaultPlotSampleCount); qCopy(phaseSum, phaseSum+defaultPlotSampleCount, yPS.begin());
    m_phaseSumGraph->setData(xPS, yPS);
}