ASK Modulated Signal Envelope (Python)

46 Views Asked by At

I'm working with an ASK modulated audio signal. I use Tkinter to open the file (in .wav) and do a simple filter through a threshold.

I would like to have the envelope graph.

Example result

import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
from tkinter import Tk
from tkinter.filedialog import askopenfilename

Tk().withdraw() 
audioFileName = askopenfilename() 

# Leitura do sinal de áudio modulado em ASK
sample_rate, audio_data = wavfile.read(audioFileName)

# Parâmetros
threshold = 16000  

# Demodulação ASK
demodulated_signal = (audio_data > threshold).astype(int)

# Plotagem dos sinais
time_axis = np.arange(len(audio_data)) / sample_rate

plt.figure(figsize=(16, 6))
plt.subplot(2, 1, 1)
plt.plot(time_axis, audio_data, color="#AD2523")
plt.title('Sinal de Áudio Capturado')
plt.xlabel('Tempo (s)')
plt.ylabel('Amplitude')
plt.subplot(2, 1, 2)
plt.plot(time_axis, demodulated_signal, color="#2B77AD")
plt.title('Sinal Demodulado (Digital)')
plt.xlabel('Tempo (s)')
plt.ylabel('Bit')
plt.tight_layout()
plt.show() 

I tried several tutorials suggesting using Hilbert, but I was unsuccessful.

analytic_signal = hilbert(demodulated_signal)
envelope = np.abs(analytic_signal)
1

There are 1 best solutions below

0
dankal444 On

What you want (in the plot you provided) is not an envelope. Your "expected signal" is rather boolean "is above energy threshold" signal than envelope.

To get this you can use running mean of the abs(signal) (or even better - energy of the signal, i.e. signal ** 2) with some arbitrary size of the running mean window.

Side note: Hilbert transform will provide you with envelope, but only if your signal is narrow band.