finished exercise except for some parts of number 1
This commit is contained in:
42
Assignment2_211/assignment2_5.m
Normal file
42
Assignment2_211/assignment2_5.m
Normal file
@@ -0,0 +1,42 @@
|
||||
% Read and play original audio
|
||||
[audio, fs] = audioread('./audio.wav');
|
||||
%sound(audio, fs);
|
||||
|
||||
% Read and play room impulse response (RIR)
|
||||
[rir, fs_rir] = audioread('./rir.wav');
|
||||
%sound(rir, fs_rir);
|
||||
|
||||
% Apply convolution (reverb effect)
|
||||
audio_reverb = conv(audio, rir);
|
||||
|
||||
%sound(audio_reverb, fs);
|
||||
|
||||
% Plot the waveforms
|
||||
figure;
|
||||
|
||||
% Original audio
|
||||
subplot(2,1,1);
|
||||
plot(audio);
|
||||
title('Original Audio');
|
||||
xlabel('Sample Number');
|
||||
ylabel('Amplitude');
|
||||
|
||||
% Reverberated audio
|
||||
subplot(2,1,2);
|
||||
plot(audio_reverb);
|
||||
title('Audio with Reverb');
|
||||
xlabel('Sample Number');
|
||||
ylabel('Amplitude');
|
||||
|
||||
% Calculate signal energy
|
||||
function [ W ] = energy( x )
|
||||
W = sum(abs(x).^2);
|
||||
end
|
||||
|
||||
energy_rir = energy(rir)
|
||||
energy_original = energy(audio)
|
||||
energy_reverb = energy(audio_reverb)
|
||||
|
||||
% Display energy values
|
||||
fprintf('Original Audio Energy: %.4f\n', energy_original);
|
||||
fprintf('Reverberated Audio Energy: %.4f\n', energy_reverb);
|
||||
Reference in New Issue
Block a user