this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove analyze scripts

alice 30311341 0e30c2bb

-104
-58
analyze_esp32_q_fixed.py
··· 1 - #!/usr/bin/env python3 2 - # Analyze effective Q factor in ESP32 approach - FIXED 3 - 4 - import math 5 - 6 - fs = 44100 # Sample rate 7 - N = 4096 # FFT size 8 - fmin = 20 # Minimum frequency 9 - 10 - print("ESP32 CQT Analysis (Corrected)") 11 - print("==============================") 12 - print(f"FFT size: {N}, Sample rate: {fs} Hz, Min freq: {fmin} Hz") 13 - print() 14 - 15 - # Test frequencies spanning 10 octaves 16 - freqs = [20, 27.5, 40, 55, 80, 110, 160, 220, 440, 880, 1760, 3520, 7040, 14080, 20000] 17 - 18 - print("Freq(Hz) | Factor | Window | Duration(ms) | Eff. Q | BW(Hz) | BW(cents)") 19 - print("---------|--------|--------|--------------|--------|--------|----------") 20 - 21 - for f in freqs: 22 - # ESP32 window calculation: N_window = N / (f/fmin) 23 - factor = f / fmin 24 - window_length = N / factor # Keep as float for accurate Q 25 - window_length_int = int(window_length) 26 - 27 - # Window duration in milliseconds 28 - duration_ms = window_length / fs * 1000 29 - 30 - # Effective Q = window_length * f / fs 31 - eff_q = window_length * f / fs 32 - 33 - # Bandwidth = f / Q 34 - bandwidth = f / eff_q 35 - 36 - # Bandwidth in cents (1 semitone = 100 cents) 37 - # cents = 1200 * log2(f2/f1) where f2 = f + bandwidth/2, f1 = f - bandwidth/2 38 - bw_cents = 1200 * math.log2((f + bandwidth/2) / (f - bandwidth/2)) 39 - 40 - print(f"{f:7.1f} | {factor:6.1f} | {window_length_int:6d} | {duration_ms:12.1f} | " 41 - f"{eff_q:6.1f} | {bandwidth:6.1f} | {bw_cents:8.0f}") 42 - 43 - print() 44 - print("Key Findings:") 45 - print("-------------") 46 - print("1. ESP32 method gives CONSTANT Q ≈ 1.86 for all frequencies!") 47 - print("2. This is about 9x lower than ideal Q ≈ 17 for 12 bins/octave") 48 - print("3. Bandwidth is constant at ~7.5 semitones (should be ~0.83 semitones)") 49 - print() 50 - print("Trade-offs:") 51 - print("- PRO: All windows fit in FFT size, simple implementation") 52 - print("- PRO: No truncation artifacts") 53 - print("- CON: Poor frequency resolution (9x worse than ideal)") 54 - print("- CON: Can't distinguish adjacent notes (bandwidth > 1 semitone)") 55 - print() 56 - print("For electronic music with 20Hz start:") 57 - print(f"- Window at 20Hz: {N/1:.0f} samples = {N/1/fs*1000:.1f}ms") 58 - print(f"- Window at 20kHz: {N/1000:.0f} samples = {N/1000/fs*1000:.1f}ms")
-46
fft_compute_analysis.py
··· 1 - #!/usr/bin/env python3 2 - # Analyze computational cost of different FFT sizes 3 - 4 - import math 5 - 6 - print("FFT Computational Cost Analysis") 7 - print("===============================") 8 - print() 9 - 10 - # FFT complexity is O(N log N) 11 - sizes = [4096, 8192, 16384, 32768, 65536] 12 - base_size = 4096 13 - 14 - print("FFT Size | Ops (N log N) | Relative Cost | Time @ 1GHz") 15 - print("---------|---------------|---------------|-------------") 16 - 17 - for N in sizes: 18 - ops = N * math.log2(N) 19 - relative = ops / (base_size * math.log2(base_size)) 20 - # Assume 10 clock cycles per complex multiply-add 21 - # Modern CPUs can do ~1 operation per clock with SIMD 22 - time_ms = (ops * 10) / (1e9) * 1000 # milliseconds at 1GHz 23 - 24 - print(f"{N:7d} | {ops:13.0f} | {relative:13.1f}x | {time_ms:10.2f}ms") 25 - 26 - print() 27 - print("Real-world estimates (with KISS FFT, no SIMD):") 28 - print("- 4096-point: ~1-2ms on modern CPU") 29 - print("- 16384-point: ~5-10ms") 30 - print("- 32768-point: ~12-24ms") 31 - print() 32 - print("For 60 FPS: 16.7ms per frame total") 33 - print("For 30 FPS: 33.3ms per frame total") 34 - print() 35 - 36 - # Memory usage 37 - print("Memory Requirements:") 38 - print("Size | Samples | Real FFT Output | Kernels (120 bins)") 39 - print("------|---------|-----------------|-------------------") 40 - for N in sizes: 41 - samples = N * 4 # float32 42 - fft_out = (N//2 + 1) * 8 # complex float32 43 - # Assume 30% sparsity for kernels 44 - kernels = 120 * (N//2 + 1) * 8 * 0.3 45 - total = (samples + fft_out + kernels) / 1024 46 - print(f"{N:5d} | {samples/1024:7.0f}K | {fft_out/1024:15.0f}K | {kernels/1024:17.0f}K (Total: {total:.0f}K)")