# First thing we want to do is anaylyze all three sound files and look for high levels of energy in the spectorgram in the ultrasonic range
#Track 2 play
import IPython.display as ipd
ipd.Audio('Ex3_sound2.wav')
#import the pyplot and wavfile modules
import matplotlib.pyplot as plot
from scipy.io import wavfile
# Track 2
# Read the wav file (mono)
samplingFrequency2, signalData2 = wavfile.read('Ex3_sound2.wav')
# Plot the signal read from wav file
plot.specgram(signalData2,Fs=samplingFrequency2)
plot.xlabel('Time')
plot.ylabel('Frequency')
plot.show()
# Track 2 has energy levels in the lower range, below 5 or 6 KHz as can be seen in the spectogram above.
# Track 3 play
ipd.Audio('Ex3_sound3.wav')
# Track 3
# Read the wav file (mono)
samplingFrequency3, signalData3 = wavfile.read('Ex3_sound3.wav')
# Plot the signal read from wav file
plot.specgram(signalData3,Fs=samplingFrequency3)
plot.xlabel('Time')
plot.ylabel('Frequency')
plot.show()
# Track 3 has energy in the higher frequency range, it's less concentrated and it's all still below 16 kHz.
# Track 4 play
ipd.Audio('Ex3_sound4.wav')
# Track 4
# Read the wav file (mono)
samplingFrequency4, signalData4 = wavfile.read('Ex3_sound4.wav')
# Plot the signal read from wav file
plot.specgram(signalData4,Fs=samplingFrequency4)
plot.xlabel('Time')
plot.ylabel('Frequency')
plot.show()
# Track 4 has concentrated energy in the higher frequency range, from 15kHz upwards. More specifically, it seems to be concentrated around 19KHz.
# This is the track we're looking for with the hidden message and it's contained within the first 2 seconds of the track.
# Now we need to find a way to shift it into the the audible frequency domain of the human ear.
# Get thinkdsp.py
import os
import thinkdsp
from thinkdsp import decorate
from thinkdsp import read_wave
# Load in sound 4 using thinkDSP
wave = read_wave('Ex3_sound4.wav')
wave.unbias()
wave.normalize()
wave.make_audio()
# Lets look at the frequency domain plot
spectrum = wave.make_spectrum()
spectrum.plot()
plt.xlabel('Frequency (Hz)');
# Above we can see the signal clearly spiking around 18 or 19 kHz.
# Lets use a high pass filter to remove all frequencies below 15kHz.
# In other words, we'll isolate the hidden signal
spectrum.high_pass(15000)
spectrum.plot(high=25000)
plt.xlabel('Frequency (Hz)');
# Now that we have the signal isolated, we need to modulate the amplitude.
# We've seen the most energy being concentrated around 19KHz, so we'll start with that frequency.
carrier_sig = thinkdsp.CosSignal(freq=19000)
carrier_wave = carrier_sig.make_wave(duration=wave.duration, framerate=wave.framerate)
carrier_spectrum = carrier_wave.make_spectrum()
carrier_spectrum.plot()
modulated = wave1 * carrier_wave
modulatedSpectrum = modulated.make_spectrum()
modulatedSpectrum.low_pass(5000)
modulatedSpectrum.plot()
plt.xlabel('Frequency (Hz)');
# Above we see the signal shifted as we expected and it seems to be more or less correct as it's centered around 0
# Let's play it and see if we can hear the coded message.
wave2 = modulatedSpectrum.make_wave()
start = 0
duration = 1.5
segment = wave2.segment(start, duration)
segment.plot()
segment.make_audio()
# Great.
# The message is pretty clear: 1891