SignalLab2/vocoder.m

79 lines
1.9 KiB
Matlab

function vocoder()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Task: To create a vocoded version
%
% Inputs: -
%
% Outputs: -
%
%
% Author: Charles Stelandre - charles.stelandre@ecam.fr
%
% Date: 01/05/2025
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
modfile = './sound/modulator22.wav';
carfile = ['./sound/white_periodic.wav'];
%outfile = 'vocodedsound.wav'
[modul, sr1] = audioread(modfile);
[carrier, sr2] = audioread(carfile);
if sr1~=sr2, disp('your sampling rates dont match'); end
y = chanvocoder(carrier, modul, 512, 16, 0.1);
%audiowrite(outfile, y, sr1);
sr = sr1; % Assuming sampling rates are the same or we proceed with the modulator's rate
% --- Play the modulator sound ---
disp('Playing the modulator sound...');
sound(modul, sr);
pause(length(modul)/sr + 0.5); % Add a small pause
% --- Play the vocoded sound ---
disp('Playing the vocoded sound...');
sound(y, sr);
% audiowrite(outfile, y, sr);
% --- Plot Temporal Variations ---
t_modul = (0:length(modul)-1) / sr;
plot(t_modul, modul);
title('Temporal Variation of Modulator');
xlabel('Time (s)');
ylabel('Amplitude');
t_carrier = (0:length(carrier)-1) / sr;
plot(t_carrier, carrier);
title('Temporal Variation of Carrier');
xlabel('Time (s)');
ylabel('Amplitude');
t_output = (0:length(y)-1) / sr;
plot(t_output, y);
title('Temporal Variation of Vocoded Output');
xlabel('Time (s)');
ylabel('Amplitude');
window_size = 30; % Example window size (20ms)
step_size = 5; % Example step size (10ms overlap)
spectrogram(modul, sr, step_size, window_size);
title('Spectrogram of Modulator');
colorbar;
ylabel('Frequency (Hz)');
xlabel('Time (s)');
spectrogram(carrier, sr, step_size, window_size);
title('Spectrogram of Carrier');
colorbar;
ylabel('Frequency (Hz)');
xlabel('Time (s)');
spectrogram(y, sr, step_size, window_size);
title('Spectrogram of Vocoded Output');
colorbar;
ylabel('Frequency (Hz)');
xlabel('Time (s)');
end