Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

recObj = audiorecorder

recDuration = 5;
disp("Begin speaking.")
recordblocking(recObj,recDuration);
disp("End of recording.")
recordedVoice = getaudiodata(recObj);

%% Generate distorted voice signals by differing k and α values


k1 = 1.5;
alpha1 = 0.8;
distortedVoice1 = distortVoice(recordedVoice, k1, alpha1);
filteredVoice1 = removeDistortion(distortedVoice1, k1, alpha1);

k2 = 2.0;
alpha2 = 0.6;
distortedVoice2 = distortVoice(recordedVoice, k2, alpha2);
filteredVoice2 = removeDistortion(distortedVoice2, k2, alpha2);

k3 = 2.5;
alpha3 = 0.4;
distortedVoice3 = distortVoice(recordedVoice, k3, alpha3);
filteredVoice3 = removeDistortion(distortedVoice3, k3, alpha3);

%% Plot both input and output. Evaluate the result


figure;
subplot(3,1,1);
plot(recordedVoice);
title('Original Voice');

subplot(3,1,2);
plot(distortedVoice1);
title('Distorted Voice 1 (k=1.5, α=0.8)');

subplot(3,1,3);
plot(filteredVoice1);
title('Filtered Voice 1');

figure;
subplot(3,1,1);
plot(recordedVoice);
title('Original Voice');
subplot(3,1,2);
plot(distortedVoice2);
title('Distorted Voice 2 (k=2.0, α=0.6)');

subplot(3,1,3);
plot(filteredVoice2);
title('Filtered Voice 2');

figure;
subplot(3,1,1);
plot(recordedVoice);
title('Original Voice');

subplot(3,1,2);
plot(distortedVoice3);
title('Distorted Voice 3 (k=2.5, α=0.4)');

subplot(3,1,3);
plot(filteredVoice3);
title('Filtered Voice 3');

function distortedVoice = distortVoice(originalVoice, k, alpha)


% Distorts the original voice signal using the given k and α values

distortedVoice = conv(originalVoice, [k - alpha; k + alpha], 'full');


end

function filteredVoice = removeDistortion(distortedVoice, k, alpha)


% Removes distortion from the distorted voice signal

filteredVoice = conv(distortedVoice, 1 / (k^2 - alpha), 'full');


filteredVoice = filteredVoice / k;
end

You might also like