% load the audio data file
[y, Fs] = audioread("secret_message.wav");
n = length(y);
dt = 1/Fs;
t = (0:(n-1))*dt; % timeline start at 0
plot(t, y); % plot the original data
title("original signal");
xlabel("time(seconds)");
% plot the spectrogram of the signal
spectrogram(y, ones(128,1), 0, 128, Fs, 'yaxis')
title('Spectrogram')
% There are many high frequencies (above 5kHz) and they barely change.
% These signal contains little information.
% See what the discrete fourier transform do to these signals.
Y = fft(y);
yMag = abs(Y);
N = length(yMag);
f = 0:(Fs/N):Fs/2;
yMag = yMag(1:length(f));
plot(f,yMag);
title("Signle-sidied Amplitude Spectrum")
xlabel("f(Hz)");
ylabel("|c_n(f)|");
% there seems to be something happening in the low frequency area.
% we can do a log-scale plot to better understand it.
semilogy(f,yMag);
title("Signle-sidied Amplitude Spectrum, logy");
xlabel("f (Hz)");
ylabel("||c_n(f)|")
% filter out the low frequency and high frequency.
signalBp = bandpass(y,[100,4300],Fs);
signalBp = 100*signalBp; % rescale to amplify the sounds produced.
sound(signalBp,Fs);