Пример #1
0
  Mm ex() {
    begin_scope
    #line 1 "d:/matcom45/ex.m"
    call_stack_begin;
    #line 1 "d:/matcom45/ex.m"
    // nargin, nargout entry code
    double old_nargin=nargin_val; if (!nargin_set) nargin_val=0.0;
    nargin_set=0;
    double old_nargout=nargout_val; if (!nargout_set) nargout_val=0.0;
    nargout_set=0;
    
    // translated code
    
    #line 2 "d:/matcom45/ex.m"
_   subplot(121.0);
    #line 3 "d:/matcom45/ex.m"
_   surf((CL(peaks(25.0))));
    #line 4 "d:/matcom45/ex.m"
_   subplot(122.0);
    #line 5 "d:/matcom45/ex.m"
_   pcolor((CL(peaks(25.0))));
    
    call_stack_end;
    
    // nargin, nargout exit code
    nargin_val=old_nargin; nargout_val=old_nargout;
    
    // function exit code
    
    return x_M;
    end_scope
  }
Пример #2
0
void NWaveformBuilderGstreamer::update()
{
	GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_playbin));
	GstMessage *msg = gst_bus_pop_filtered(bus, GstMessageType(GST_MESSAGE_EOS | GST_MESSAGE_ERROR));
	if (msg) {
		switch (GST_MESSAGE_TYPE(msg)) {
			case GST_MESSAGE_EOS:
				peaks()->complete();
#if defined(QT_DEBUG) && !defined(QT_NO_DEBUG)
				qDebug() <<  "WaveformBuilder ::" << "completed" << peaks()->size();
#endif
				stop();
				break;
			case GST_MESSAGE_ERROR:
#if defined(QT_DEBUG) && !defined(QT_NO_DEBUG)
				gchar *debug;
				GError *err = NULL;

				gst_message_parse_error(msg, &err, &debug);
				g_free(debug);

				qWarning() << "WaveformBuilder :: error ::" << QString::fromUtf8(err->message);
				if (err)
					g_error_free(err);
#endif
				break;
			default:
				break;
		}
		gst_message_unref(msg);
	}
	gst_object_unref(bus);
}
Пример #3
0
//________________________________________________________________________________
void FindPeaks(Int_t np=10) {
  TString Out("Results.");
  Out += gSystem->BaseName(gDirectory->GetName());
  Out.ReplaceAll(".root","");
  Out.ReplaceAll(" ","");
  out.open(Out, ios::out);
  TIter nextkey(gDirectory->GetListOfKeys() );
  TKey *key;
  Int_t i = 0;
  Int_t nhists = 0;
  while ((key = (TKey*) nextkey())) {
    TObject *obj = key->ReadObj();
    if (! obj->IsA()->InheritsFrom( "TH1" ) ) continue;
    TH1 *h1 = (TH1*)obj;
    if (h1->GetEntries() < 1000) continue;
    nhists++;
  }
  Int_t nxy = nhists;
  Int_t nx =  (Int_t) TMath::Sqrt(nxy) + 1;
  Int_t ny = nxy/nx + 1;
  c2 = new TCanvas("Anodes","Anodes");
  c2->Divide(nx,ny);
  nextkey.Reset();
  Int_t histNo = 1;
  while ((key = (TKey*) nextkey())) {
    TObject *obj = key->ReadObj();
    if (! obj->IsA()->InheritsFrom( "TH1" ) ) continue;
    if ( obj->IsA()->InheritsFrom( "TH1C" ) ||
	 obj->IsA()->InheritsFrom( "TH1S" ) ||
	 obj->IsA()->InheritsFrom( "TH1I" ) ||
	 obj->IsA()->InheritsFrom( "TH1F" ) ) {
      cout << "Found histogram " << obj->GetName() << endl;
      TH1 *h1 = (TH1*)obj;
      if (h1->GetEntries() < 1000) {
	TString LineH("  {\"");  LineH +=  h1->GetName(); LineH += "\"";
	TString Line("");
	LineH +=  ",-99";
	for (Int_t p = 0; p < np; p++) Line += ",0,0";
	Line += "},// dead";
	cout << LineH << Line << endl;
	out  << LineH << Line << endl;
	continue;
      }
      peaks(h1,np,histNo);
      histNo++;
      //      break;
      if (i < 99) {
	cout << "Type something" << endl;
	cin >> i;
	if (i <= 0) break;
      }
    }
Пример #4
0
void Analyzer::calcTones() {
    // Precalculated constants
    const double freqPerBin = m_rate / FFT_N;
    const double phaseStep = 2.0 * M_PI * m_step / FFT_N;
    const double normCoeff = 1.0 / FFT_N;
    const double minMagnitude = pow(10, -100.0 / 20.0) / normCoeff; // -100 dB
    // Limit frequency range of processing
    const size_t kMin = std::max(size_t(1), size_t(FFT_MINFREQ / freqPerBin));
    const size_t kMax = std::min(FFT_N / 2, size_t(FFT_MAXFREQ / freqPerBin));
    std::vector<Peak> peaks(kMax + 1); // One extra to simplify loops
    for (size_t k = 1; k <= kMax; ++k) {
        double magnitude = std::abs(m_fft[k]);
        double phase = std::arg(m_fft[k]);
        // process phase difference
        double delta = phase - m_fftLastPhase[k];
        m_fftLastPhase[k] = float(phase);
        delta -= k * phaseStep;  // subtract expected phase difference
        delta = remainder(delta, 2.0 * M_PI);  // map delta phase into +/- M_PI interval
        delta /= phaseStep;  // calculate diff from bin center frequency
        double freq = (k + delta) * freqPerBin;  // calculate the true frequency
        if (freq > 1.0 && magnitude > minMagnitude) {
            peaks[k].freq = freq;
            peaks[k].db = 20.0 * log10(normCoeff * magnitude);
        }
    }
    // Prefilter peaks
    double prevdb = peaks[0].db;
    for (size_t k = 1; k < kMax; ++k) {
        double db = peaks[k].db;
        if (db > prevdb) peaks[k - 1].clear();
        if (db < prevdb) peaks[k].clear();
        prevdb = db;
    }
    // Find the tones (collections of harmonics) from the array of peaks
    tones_t tones;
    for (size_t k = kMax - 1; k >= kMin; --k) {
        if (peaks[k].db < -70.0) continue;
        // Find the best divider for getting the fundamental from peaks[k]
        std::size_t bestDiv = 1;
        int bestScore = 0;
        for (std::size_t div = 2; div <= Tone::MAXHARM && k / div > 1; ++div) {
            double freq = peaks[k].freq / div; // Fundamental
            int score = 0;
            for (std::size_t n = 1; n < div && n < 8; ++n) {
                Peak& p = match(peaks, k * n / div);
                --score;
                if (p.db < -90.0 || std::abs(p.freq / n / freq - 1.0) > .03) continue;
                if (n == 1) score += 4; // Extra for fundamental
                score += 2;
            }
            if (score > bestScore) {
                bestScore = score;
                bestDiv = div;
            }
        }
        // Construct a Tone by combining the fundamental frequency (freq) and all harmonics
        Tone t;
        std::size_t count = 0;
        double freq = peaks[k].freq / bestDiv;
        t.db = peaks[k].db;
        for (std::size_t n = 1; n <= bestDiv; ++n) {
            // Find the peak for n'th harmonic
            Peak& p = match(peaks, k * n / bestDiv);
            if (std::abs(p.freq / n / freq - 1.0) > .03) continue; // Does it match the fundamental freq?
            if (p.db > t.db - 10.0) {
                t.db = std::max(t.db, p.db);
                ++count;
                t.freq += p.freq / n;
            }
            t.harmonics[n - 1] = p.db;
            p.clear();
        }
        t.freq /= count;
        // If the tone seems strong enough, add it (-3 dB compensation for each harmonic)
        if (t.db > -50.0 - 3.0 * count) {
            t.stabledb = t.db;
            tones.push_back(t);
        }
    }
    mergeWithOld(tones);
    m_tones.swap(tones);
}