CommProj_Trial_1.01
unknown
matlab
2 years ago
3.6 kB
5
Indexable
% C O M M P R O J E C T 2 0 2 3 %-------------------------------- T h e S i g n a l s ----------------------- %Loading all audio files and getting their sampling frequencies %Note that they all have the same sampling frequency of 44100 Hz [raw_audio_1, Fs1] = audioread('OriginalAudios/Short_BBCArabic2.wav'); [raw_audio_2, Fs2] = audioread('OriginalAudios/Short_FM9090.wav'); [raw_audio_3, Fs3] = audioread('OriginalAudios/Short_QuranPalestine.wav'); [raw_audio_4, Fs4] = audioread('OriginalAudios/Short_RussianVoice.wav'); [raw_audio_5, Fs5] = audioread('OriginalAudios/Short_SkyNewsArabia.wav'); %Adjusting lengths to be able to generalize the next operations max_length = length(raw_audio_1); %longest audio is the first one raw_audio_2(max_length, 1) = 0; raw_audio_2(max_length, 2) = 0; %padding short audios with zeros raw_audio_3(max_length, 1) = 0; raw_audio_3(max_length, 2) = 0; raw_audio_4(max_length, 1) = 0; raw_audio_4(max_length, 2) = 0; raw_audio_5(max_length, 1) = 0; raw_audio_5(max_length, 2) = 0; %Creating array of audios to better automate next operations raw_audio = [raw_audio_1, raw_audio_2, raw_audio_3, raw_audio_4, raw_audio_5]; %Stereo to mono conversion raw_audio_mono = zeros(max_length, 5); for n = 1:5 stereo_audio = [raw_audio(:, 2*n-1),raw_audio(:, 2*n)]; raw_audio_mono(:, n) = stereo2mono(stereo_audio); end %Computing and plotting the fast Fourier transform for n = 1:5 fourier_transform(raw_audio_mono(:, n), max_length, Fs1); end %------------------------------ T h e A M M o d u l a t o r ----------------------- %Increasing sampling frequency by 16 times to be able to do FDM with fc = 100 kHz Fs_x16 = Fs1 * 16; length_x16 = max_length * 16; mono_audio_sampled_x16 = zeros(length_x16, 5); for n = 1:5 mono_audio_sampled_x16(:, n) = interp(raw_audio_mono(:, n), 16); end %DSB-SC AM t = 1/Fs_x16:1/Fs_x16:length_x16/Fs_x16; mono_audio_modulated = zeros(length_x16, 5); for n = 1:5 fc = 1e5 + (n-1) * 55e3; carrier = cos(2*pi*t*fc)'; message = mono_audio_sampled_x16(:, n); mono_audio_modulated(:, n) = carrier.*message; end %Computing and plotting the fast Fourier transform for n = 1:5 fourier_transform(mono_audio_modulated(:, n), length_x16, Fs_x16); end %Constructing the message transmitted_message = zeros(length_x16, 1); for n = 1:5 transmitted_message = transmitted_message + mono_audio_modulated(:, n); end %Computing and plotting the fast Fourier transform fourier_transform(transmitted_message, length_x16, Fs_x16); %----------------------------- F u n c t i o n s ------------------------------ %Function to create single channel audio (stereo to mono conversion) function audio_mono = stereo2mono(audio_stereo) left_channel = audio_stereo(:, 1); right_channel = audio_stereo(:, 2); audio_mono = left_channel + right_channel; end %Function to compute and plot Fourier transform of x signal with Fsx sampling frequency and Nx samples function fourier_transform (x, Nx, Fsx) x_fft = fft(x); x_fft_shifted = fftshift(x_fft); % shifting the zero frequency component to the center magnitude_spectrum = abs(x_fft_shifted) / Nx; %normalizing by the number of samples frequency_shifted = linspace(-Fsx/2, Fsx/2, Nx); %editing the frequency axis figure; plot(frequency_shifted, magnitude_spectrum); title('Fast Fourier Transform'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); grid on; end
Editor is loading...
Leave a Comment