Uncategorized

Standalone Python script to generate two synthetic signals and performs FFT-based correlation.

Here’s a standalone Python script you can run on your Linux system later. It generates two synthetic signals, performs FFT-based correlation, and saves the result to a timestamped .npy file in ~/InterferometryData.


📜 Full Script: fft_correlation_pipeline.py

import numpy as np
from scipy.fft import fft, ifft
import os
import time
 
def fft_correlate_save(a, b, output_path="fft_correlation_output.npy"):
    """Perform FFT-based cross-correlation and save result to file."""
    n = len(a) + len(b) - 1
    fa = fft(a, n=n)
    fb = fft(b, n=n)
    correlation = ifft(fa * np.conj(fb)).real
    np.save(output_path, correlation)
    return correlation
 
def run_fft_correlation_pipeline(sample_count=1_000_000, output_dir="~/InterferometryData"):
    """Generate two signals, run FFT-based correlation, save result."""
    output_dir = os.path.expanduser(output_dir)
    os.makedirs(output_dir, exist_ok=True)
 
    # Generate synthetic signals (can replace with real data)
    np.random.seed(42)
    signal_a = np.random.normal(0, 1, sample_count).astype(np.float32)
    signal_b = np.random.normal(0, 1, sample_count).astype(np.float32)
 
    # Timestamped output filename
    timestamp = time.strftime("%Y%m%d_%H%M%S")
    output_file = os.path.join(output_dir, f"fft_corr_{timestamp}.npy")
 
    print(f"Running FFT-based correlation on {sample_count} samples...")
    start = time.time()
    result = fft_correlate_save(signal_a, signal_b, output_file)
    end = time.time()
    print(f"Done in {end - start:.2f} seconds.")
    print(f"Saved to: {output_file}")
 
    # Optional: preview first few values
    print("First 5 values of result:")
    print(result[:5])
 
if __name__ == "__main__":
    run_fft_correlation_pipeline()

✅ Usage

  1. Save as: fft_correlation_pipeline.py
  2. On your Linux machine, run:
3.  python3 fft_correlation_pipeline.py
  1. Result will be saved in:
5.  ~/InterferometryData/

as a .npy file with the timestamp in its name.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.