Search in sources :

Example 1 with HanningWindow

use of org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow in project cineast by vitrivr.

the class MFCCShingle method getFeatures.

/**
 * Derives and returns a list of MFCC features for a SegmentContainer.
 *
 * @param segment SegmentContainer to derive the MFCC features from.
 * @return List of MFCC Shingles.
 */
private List<float[]> getFeatures(SegmentContainer segment) {
    final Pair<Integer, Integer> parameters = FFTUtil.parametersForDuration(segment.getSamplingrate(), WINDOW_SIZE);
    final STFT stft = segment.getSTFT(parameters.first, (parameters.first - 2 * parameters.second) / 2, parameters.second, new HanningWindow());
    if (stft == null) {
        return new ArrayList<>(0);
    }
    final List<MFCC> mfccs = MFCC.calculate(stft);
    int vectors = mfccs.size() - SHINGLE_SIZE;
    List<float[]> features = new ArrayList<>(Math.max(1, vectors));
    if (vectors > 0) {
        for (int i = 0; i < vectors; i++) {
            float[] feature = new float[SHINGLE_SIZE * 13];
            for (int j = 0; j < SHINGLE_SIZE; j++) {
                MFCC mfcc = mfccs.get(i + j);
                System.arraycopy(mfcc.getCepstra(), 0, feature, 13 * j, 13);
            }
            if (MathHelper.checkNotZero(feature) && MathHelper.checkNotNaN(feature)) {
                features.add(MathHelper.normalizeL2(feature));
            }
        }
    }
    return features;
}
Also used : ArrayList(java.util.ArrayList) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) MFCC(org.vitrivr.cineast.core.util.audio.MFCC)

Example 2 with HanningWindow

use of org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow in project cineast by vitrivr.

the class HPCPShingle method getFeatures.

/**
 * Returns a list of feature vectors given a SegmentContainer.
 *
 * @param segment SegmentContainer for which to calculate the feature vectors.
 * @return List of HPCP Shingle feature vectors.
 */
private List<float[]> getFeatures(SegmentContainer segment) {
    /* Create STFT; If this fails, return empty list. */
    Pair<Integer, Integer> parameters = FFTUtil.parametersForDuration(segment.getSamplingrate(), WINDOW_SIZE);
    STFT stft = segment.getSTFT(parameters.first, (parameters.first - 2 * parameters.second) / 2, parameters.second, new HanningWindow());
    if (stft == null) {
        return new ArrayList<>(0);
    }
    HPCP hpcps = new HPCP(this.resolution, this.min_frequency, this.max_frequency);
    hpcps.addContribution(stft);
    int vectors = Math.max(hpcps.size() - SHINGLE_SIZE, 1);
    final SummaryStatistics statistics = new SummaryStatistics();
    List<Pair<Double, float[]>> features = new ArrayList<>(vectors);
    for (int n = 0; n < vectors; n++) {
        Pair<Double, float[]> feature = this.getHPCPShingle(hpcps, n);
        features.add(feature);
        statistics.addValue(feature.first);
    }
    final double threshold = 0.25 * statistics.getGeometricMean();
    return features.stream().filter(f -> (f.first > threshold)).map(f -> f.second).collect(Collectors.toList());
}
Also used : StagedFeatureModule(org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule) MathHelper(org.vitrivr.cineast.core.util.math.MathHelper) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) FloatVectorImpl(org.vitrivr.cineast.core.data.FloatVectorImpl) HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) FFTUtil(org.vitrivr.cineast.core.util.dsp.fft.FFTUtil) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HPCP(org.vitrivr.cineast.core.util.audio.HPCP) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) List(java.util.List) SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) Pair(org.vitrivr.cineast.core.data.Pair) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) ArrayList(java.util.ArrayList) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) HPCP(org.vitrivr.cineast.core.util.audio.HPCP) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) Pair(org.vitrivr.cineast.core.data.Pair)

Example 3 with HanningWindow

use of org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow in project cineast by vitrivr.

the class WindowFunctionTest method testHanningWindow.

@Test
@DisplayName("Hanning Window Test")
void testHanningWindow() {
    HanningWindow window = new HanningWindow();
    this.executeTest(window, 512);
    this.executeTest(window, 1024);
    this.executeTest(window, 2048);
    this.executeTest(window, 4096);
}
Also used : HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with HanningWindow

use of org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow in project cineast by vitrivr.

the class MelodyEstimate method transcribe.

private Melody transcribe(SegmentContainer sc) {
    /* Calculate STFT and apply spectral whitening. */
    Pair<Integer, Integer> parameters = FFTUtil.parametersForDuration(sc.getSamplingrate(), WINDOW_SIZE);
    STFT stft = sc.getSTFT(parameters.first, 0, parameters.second, new HanningWindow());
    stft.applyFilter(new SpectralWhiteningFilter(stft.getWindowsize(), stft.getSamplingrate(), 0.33f, 30));
    float time = stft.timeStepsize();
    /* Prepare necessary helper data-structures. */
    final List<List<Pitch>> s = this.estimator.estimatePitch(stft);
    this.tracker.initialize(s, time);
    this.tracker.trackPitches();
    return this.tracker.extractMelody(10);
}
Also used : SpectralWhiteningFilter(org.vitrivr.cineast.core.util.dsp.filter.frequency.SpectralWhiteningFilter) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) ArrayList(java.util.ArrayList) List(java.util.List) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow)

Example 5 with HanningWindow

use of org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow in project cineast by vitrivr.

the class AudioFingerprint method filterSpectrum.

private TIntArrayList filterSpectrum(SegmentContainer segment) {
    /* Prepare empty list of candidates for filtered spectrum. */
    TIntArrayList candidates = new TIntArrayList();
    /* Perform STFT and extract the Spectra. If this fails, return empty list. */
    Pair<Integer, Integer> properties = FFTUtil.parametersForDuration(segment.getSamplingrate(), WINDOW_SIZE);
    STFT stft = segment.getSTFT(properties.first, (properties.first - 2 * properties.second) / 2, properties.second, new HanningWindow());
    if (stft == null) {
        return candidates;
    }
    List<Spectrum> spectra = stft.getPowerSpectrum();
    /* Foreach spectrum; find peak-values in the defined ranges. */
    for (Spectrum spectrum : spectra) {
        int spectrumidx = 0;
        for (int j = 0; j < RANGES.length - 1; j++) {
            Pair<Float, Double> peak = null;
            for (int k = spectrumidx; k < spectrum.size(); k++) {
                Pair<Float, Double> bin = spectrum.get(k);
                if (bin.first >= RANGES[j] && bin.first <= RANGES[j + 1]) {
                    if (peak == null || bin.second > peak.second) {
                        peak = bin;
                    }
                } else if (bin.first > RANGES[j + 1]) {
                    spectrumidx = k;
                    break;
                }
            }
            candidates.add(Math.round(peak.first - (peak.first.intValue() % 2)));
        }
    }
    return candidates;
}
Also used : STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) TIntArrayList(gnu.trove.list.array.TIntArrayList) Spectrum(org.vitrivr.cineast.core.util.dsp.fft.Spectrum)

Aggregations

HanningWindow (org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow)10 STFT (org.vitrivr.cineast.core.util.dsp.fft.STFT)9 HPCP (org.vitrivr.cineast.core.util.audio.HPCP)5 ArrayList (java.util.ArrayList)4 BufferedImage (java.awt.image.BufferedImage)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 List (java.util.List)2 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)2 FloatVectorImpl (org.vitrivr.cineast.core.data.FloatVectorImpl)2 Spectrum (org.vitrivr.cineast.core.util.dsp.fft.Spectrum)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 HashMap (java.util.HashMap)1 Collectors (java.util.stream.Collectors)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)1 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)1 CorrespondenceFunction (org.vitrivr.cineast.core.data.CorrespondenceFunction)1 Pair (org.vitrivr.cineast.core.data.Pair)1