void Analyzer::init() { setState(Loading); if (m_sampleSize != (quint32)KTunerConfig::segmentLength()) { m_sampleSize = KTunerConfig::segmentLength(); m_outputSize = m_sampleSize + 1; m_window.resize(m_sampleSize); m_input.resize(2 * m_sampleSize); m_output.resize(m_outputSize); m_spectrum.resize(m_outputSize); m_noiseSpectrum.resize(m_outputSize); // FFTW and C++(99) complex types are binary compatible auto output = reinterpret_cast<fftw_complex*>(m_output.data()); m_plan = fftw_plan_dft_r2c_1d(m_input.size(), m_input.data(), output, FFTW_MEASURE); m_ifftPlan = fftw_plan_dft_c2r_1d(m_input.size(), output, m_input.data(), FFTW_ESTIMATE); } if (m_numSpectra != (quint32)KTunerConfig::numSpectra()) { m_numSpectra = KTunerConfig::numSpectra(); m_currentSpectrum %= m_numSpectra; m_spectrumHistory.fill(m_spectrum, m_numSpectra); } m_binFreq = qreal(KTunerConfig::sampleRate()) / m_input.size(); calculateWindow(); setNoiseFilter(KTunerConfig::enableNoiseFilter()); setFftFilter(); setState(Ready); }
SpectrumAnalyserThread::SpectrumAnalyserThread(QObject *parent) : QObject(parent) , set(Settings::instance()) , m_numSamples(SpectrumLengthSamples) , m_windowFunction(DefaultWindowFunction) , m_window(SpectrumLengthSamples, 0.0) , m_input(SpectrumLengthSamples, 0.0) , m_output(SpectrumLengthSamples, 0.0) , m_spectrum(SpectrumLengthSamples) #ifdef SPECTRUM_ANALYSER_SEPARATE_THREAD , m_thread(new QThread(this)) #endif { #ifdef SPECTRUM_ANALYSER_SEPARATE_THREAD // moveToThread() cannot be called on a QObject with a parent setParent(0); moveToThread(m_thread); m_thread->start(); #endif //m_cpxInput = mallocCPX(SpectrumLengthSamples); m_cpxInput.resize(SpectrumLengthSamples); //m_cpxOutput = mallocCPX(SpectrumLengthSamples); m_cpxOutput.resize(SpectrumLengthSamples); m_fft = new QFFT(SpectrumLengthSamples); //memset(m_cpxInput, 0, SpectrumLengthSamples * sizeof(CPX)); //memset(m_cpxOutput, 0, SpectrumLengthSamples * sizeof(CPX)); calculateWindow(); }
SpectrumAnalyserThread::SpectrumAnalyserThread(QObject *parent) : QObject(parent) #ifndef DISABLE_FFT , m_fft(new FFTRealWrapper) #endif , m_numSamples(SpectrumLengthSamples) , m_windowFunction(DefaultWindowFunction) , m_window(SpectrumLengthSamples, 0.0) , m_input(SpectrumLengthSamples, 0.0) , m_output(SpectrumLengthSamples, 0.0) , m_spectrum(SpectrumLengthSamples) #ifdef SPECTRUM_ANALYSER_SEPARATE_THREAD , m_thread(new QThread(this)) #endif { #ifdef SPECTRUM_ANALYSER_SEPARATE_THREAD moveToThread(m_thread); m_thread->start(); #endif calculateWindow(); }
void SpectrumAnalyserThread::setWindowFunction(WindowFunction type) { m_windowFunction = type; calculateWindow(); }
void KaiserWindowDesigner::getWindow(RealArray &w) { w.resize(size); Real beta = getBeta(); calculateWindow(w, beta); }
// This function determines which command to issue next based on our // policy decisions. void policyManager(FILE *ofile) { command chosenCommand = WAIT; command nextCommand; bool isLegal = TRUE; int chosenPriority = -2; int comparePriority = 0; int chosenIndex; int queueIndex; // Check for a starving command and give it priority if it is legal. int starveCheck = findStarvation(); if (starveCheck != -1) { chosenIndex = starveCheck; chosenCommand = findNextCommand(starveCheck); chosenPriority = 10; // Update starving struct with info starvationStatus.isCommandStarving = TRUE; starvationStatus.name = chosenCommand; starvationStatus.bank = requestQueue[chosenIndex].bank; // Determine and store window that is locked out to other banks calculateWindow(starvationStatus.name, starvationStatus.bank, &starvationStatus.lowerWindow, &starvationStatus.upperWindow); // If command is not legal assign a WAIT command and low priority. if (!isCommandLegal(chosenCommand, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].row, chosenIndex, TRUE)) { chosenCommand = WAIT; chosenPriority = -1; } } else { // No starving requests. starvationStatus.isCommandStarving = FALSE; } // Look through queue and find highest priority legal commands. for (queueIndex = 0; queueIndex < 16; ++queueIndex) { // Array element must be valid and not the most starving request. if (requestQueue[queueIndex].occupied && !requestQueue[queueIndex].finished && queueIndex != starveCheck) { nextCommand = findNextCommand(queueIndex); isLegal = isCommandLegal(nextCommand, requestQueue[queueIndex].bank, requestQueue[queueIndex].row, queueIndex, FALSE); // Skip illegal commands. if (!isLegal) continue; // Assign priority based on command. switch(nextCommand) { case PRE : comparePriority = prechargePriority(queueIndex); break; case ACT : comparePriority = 2; break; case RD : comparePriority = 4; break; case WR : comparePriority = 4; break; case WAIT: comparePriority = -1; default : printf("\nERROR: Unknown Command\n"); } // Keep highest priority command. if (comparePriority > chosenPriority) { chosenPriority = comparePriority; chosenIndex = queueIndex; chosenCommand = nextCommand; } // The oldest request wins if priority tie. else if (comparePriority == chosenPriority) { if (requestQueue[queueIndex].timeIssued < requestQueue[chosenIndex].timeIssued) { chosenIndex = queueIndex; chosenCommand = nextCommand; } } } } // Print the correct output based on command chosen. switch (chosenCommand) { case PRE: fprintf(ofile, "%llu\tPRE\t%d\n", currentCPUTick, requestQueue[chosenIndex].bank); updateDimmStatus(chosenCommand, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].row); updateTimers(chosenCommand, requestQueue[chosenIndex].bank); break; case ACT: fprintf(ofile, "%llu\tACT\t%d\t%d\n", currentCPUTick, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].row); updateDimmStatus(chosenCommand, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].row); updateTimers(chosenCommand, requestQueue[chosenIndex].bank); break; case RD: fprintf(ofile, "%llu\tRD\t%d\t%d\n", currentCPUTick, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].column); requestQueue[chosenIndex].finished = TRUE; // Read requests will stay until data is finished. requestQueue[chosenIndex].timeRemaining = tCAS + tBURST; updateDimmStatus(chosenCommand, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].row); updateTimers(chosenCommand, requestQueue[chosenIndex].bank); break; case WR: fprintf(ofile, "%llu\tWR\t%d\t%d\n", currentCPUTick, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].column); requestQueue[chosenIndex].finished = TRUE; requestQueue[chosenIndex].occupied = FALSE; countSlotsOccupied -= 1; updateDimmStatus(chosenCommand, requestQueue[chosenIndex].bank, requestQueue[chosenIndex].row); updateTimers(chosenCommand, requestQueue[chosenIndex].bank); break; default: //printf("CPU:%llu ---\n", currentCPUTick); incrementTimers(1); break; } }