%%
load mod.mat
load noisy.mat
%%
mod_play(noisy);

%%
Len = length(mod);
F_s = 811025;
f = F_s *(-Len/2 : Len/2- 1) / Len;
Mod_Freq = fft(mod);
Noisy_Freq = fft(noisy);
figure
plot(f,abs(fftshift(Mod_Freq)));
xlim([0 2.5*10^5])
figure
plot(f,abs(fftshift(Noisy_Freq)));
xlim([0 7000])

%%
k = 1;
fk = k*25000;
Filtered_Signal = Mod_Freq .* HW3_Filter(f, fk-10000, fk+10000);
figure
plot(f,abs(fftshift(Filtered_Signal)))
filtered_signal = real(ifft(Filtered_Signal));

t = (0:Len-1) / F_s;
demod_signal = filtered_signal .* (2 *cos(2*pi*fk*t));

Demod_Signal = fft(demod_signal);
Message = Demod_Signal .* HW3_Filter(f, 0, 10000);

message = real(ifft(Message));
mod_play(message);