0% found this document useful (0 votes)
40 views14 pages

AudioComm PE Vaibhav

The document describes tasks for an audio communication project including transmitting and receiving modulated audio signals. It provides: 1) Details on transmitting a UART data stream using Amplitude-Shift Keying (ASK) modulation at 15kHz, including transmitting one byte every 0.1 seconds with a 0.5 second delay between packets. 2) Instructions for receiving the transmitted audio signal over 10 seconds and displaying the raw recorded microphone data. 3) A request to create a presentation showing the raw receiver data for modulation frequencies of 15kHz, 10kHz, and 18kHz.

Uploaded by

24vaibhavtiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views14 pages

AudioComm PE Vaibhav

The document describes tasks for an audio communication project including transmitting and receiving modulated audio signals. It provides: 1) Details on transmitting a UART data stream using Amplitude-Shift Keying (ASK) modulation at 15kHz, including transmitting one byte every 0.1 seconds with a 0.5 second delay between packets. 2) Instructions for receiving the transmitted audio signal over 10 seconds and displaying the raw recorded microphone data. 3) A request to create a presentation showing the raw receiver data for modulation frequencies of 15kHz, 10kHz, and 18kHz.

Uploaded by

24vaibhavtiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Audio Communication

MT2023524- VAIBHAV TIWARI


Tasks this week:
 Transmitter
- The transmitter should send continuously one byte of data in UART format.
Baud rate = 1/(0.1) second.
- Between two UART packet, there should be a delay of 500ms
- ASK format
- Logic-High: 1.2V, 15KHz
- Logic-Low: 0V, 15KHz

 Receiver
- Once started, records the data for 10 seconds.
- Display the raw recorded microphone data.

 Create a PPT.
- Display the raw recorded microphone data for freq = 15KHz, 10KHz and 18KHz
BLOCK DIAGRAM FOR AUDIO COMMUNICATION

TRANSMITTER RECEIVER

Data in Data in
Binary ASK ASK Binary
UART UART
Data Modulation Demodulation Data
Protocol Protocol
PYTHON CODE FOR TRANSMISSION
OF ASK AUDIO SIGNAL
import numpy as np
import sounddevice as sd
import matplotlib.pyplot as plt

def generate_ask_signal(bits, duration, sample_rate, frequency, amplitude_0, amplitude_1):


t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
signal = np.zeros_like(t)

for i, bit in enumerate(bits):


amplitude = amplitude_1 if bit == '1' else amplitude_0
signal[i * int(len(t) // len(bits)): (i + 1) * int(len(t) // len(bits))] = amplitude

modulated_signal = signal * np.sin(2 * np.pi * frequency * t)


return t, modulated_signal

def generate_uart_packet(data, bit_duration, sample_rate, frequency, amplitude_0, amplitude_1):


stop_bit = '1'
packet_duration = (len(data) + 2) * bit_duration # Add start and stop bits
t = np.linspace(0, packet_duration, int(sample_rate * packet_duration), endpoint=False)
signal = np.zeros_like(t)

# Add start bit


signal[:int(bit_duration * sample_rate)] = amplitude_0

# Add data bits


for i, bit in enumerate(data):
amplitude = amplitude_1 if bit == '1' else amplitude_0
signal[int((i + 1) * bit_duration * sample_rate): int((i + 2) * bit_duration * sample_rate)] = amplitude

# Add stop bit


signal[int((len(data) + 1) * bit_duration * sample_rate):] = amplitude_1
modulated_signal = signal * np.sin(2 * np.pi * frequency * t)
return t, modulated_signal

def play_audio(signal, sample_rate):


sd.play(signal, samplerate=sample_rate)
sd.wait()

def plot_waveform(t, signal):


plt.figure(figsize=(10, 4))
plt.plot(t, signal)
plt.title('UART-Transmitted Signal')
plt.xlabel('Time (seconds)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show() # Open a window to display the plot interactively

if __name__ == "__main__":
# Constants
bits = '10101010'
bit_duration = 0.1 # Set bit duration to 0.1 seconds
sample_rate = 44100 # audio sample rate
frequency = 18000 # Change modulation frequency to 10 kHz
amplitude_0 = 0 # amplitude for bit '0' (Logic-Low)
amplitude_1 = 1.2 # amplitude for bit '1' (Logic-High)
# Generate the continuous signal with start and stop bits between each "10101010"
continuous_signal = []

for _ in range(10): # Repeat the pattern 10 times


# Generate UART-modulated signal for the packet
t, uart_signal = generate_uart_packet(bits, bit_duration, sample_rate, frequency, amplitude_0, amplitude_1)
continuous_signal.extend(uart_signal)

# Add logic high for 0.5 seconds after the stop bit
gap_bits = '1' * int(0.5 / bit_duration)
gap_t, gap_signal = generate_ask_signal(gap_bits, 0.5, sample_rate, frequency, amplitude_0, amplitude_1)
continuous_signal.extend(gap_signal)

# Play the combined signal


play_audio(continuous_signal, sample_rate)

# Plot the waveform interactively


plot_waveform(np.linspace(0, len(continuous_signal) / sample_rate, len(continuous_signal)), continuous_signal)
Transmitted audio signal
PYTHON CODE FOR RECEPTION OF ASK SIGNAL
& PLOTTING ITS BINARY DATA
import numpy as np
import matplotlib.pyplot as plt
import sounddevice as sd

def record_audio(duration, fs):


print("Recording...")
# Record audio
audio_data = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='float32')
# Wait until recording is complete
sd.wait()
print("Recording complete.")
return audio_data[:, 0]

# Sampling frequency
fs = 44100 # You can adjust this according to your needs
# Duration of recording in seconds
duration = 18 # Change this to the desired duration

# Record audio
audio_data = record_audio(duration, fs)

# Convert audio data to mono if it's stereo


if audio_data.ndim > 1:
audio_data = np.mean(audio_data, axis=1)
# Normalize the audio data to be between -1 and 1
normalized_audio_data = audio_data / np.max(np.abs(audio_data))

# Create a time axis for raw ASK waveform


time_axis_raw = np.arange(len(normalized_audio_data)) / fs

# Plot the raw ASK waveform with respect to time


plt.figure(figsize=(12, 6))

# Plot the raw ASK waveform


plt.subplot(2, 1, 1)
plt.plot(time_axis_raw, normalized_audio_data)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.title('Raw ASK Waveform vs Time')
plt.grid(True)
plt.ylim(-1.2, 1.2) # Set the y-axis limits to match the desired amplitude range

# Plot the binary array with respect to time


average_amplitude = 0.3
binary_array = np.where(np.abs(normalized_audio_data) >= average_amplitude, 1, 0)
idle_state = np.ones(int(fs * 0.1))
binary_array = np.concatenate((idle_state, binary_array))
time_axis_binary = np.arange(len(binary_array)) / fs

plt.subplot(2, 1, 2)
plt.plot(time_axis_binary, binary_array)
plt.xlabel('Time (s)')
plt.ylabel('Binary Array (1 for above or equal to average, 0 for below average)')
plt.title('Binary Array vs Time')
plt.grid(True)

plt.tight_layout()
plt.show()
OUTPUT FOR 10kHz
OUTPUT FOR 15kHz
OUTPUT FOR 18kHz

You might also like