Including Distortion with Audio Signal

8 views (last 30 days)
Dominick Metro
Dominick Metro on 2 Apr 2019
Answered: Mathieu NOE on 29 Mar 2021
I am new to MATLAB and am attempting to distort an mp3 file. I found code for distortion but I don't know how to implement the function with my signal. How do i pass the signal into the distortion? Distortion code I am using is below but I'm open to change it if need be.
function [y] = fuzz(x, Fs)
% Distortion based on an exponential function
% x - input
% gain - amount of distortion,
% mix - mix of original and distorted sound
%1=only distorted
gain = 11;
mix = 0.1;
q=x./abs(x);
y=q.*(1-exp(gain*(q.*x)));
y=mix*y+(1-mix)*x;
end

Answers (1)

Mathieu NOE
Mathieu NOE on 29 Mar 2021
hello
this is an example how to use your function within a main code
but I guess the implementation for the distortion is not correct , the result was making my ears bleed...
had to reduce "gain" factor but even then I got only "scratches"
clearvars;
close all;
infile='DirectGuitar.wav';
outfile='out_dist.wav';
% read the sample waveform
[x,Fs] = audioread(infile);
% normalize x to +/- 1 amplitude
x = x ./ (max(abs(x)));
[y] = fuzz(x, Fs);
% write output
% normalize y to +/- 1 amplitude
y = y ./ (max(abs(y)));
audiowrite(outfile, y, Fs);
figure(1)
hold on
plot(x,'r');
plot(y,'b');
title('Distorded and original Signal');
sound(y,Fs);
function [y] = fuzz(x, Fs)
% Distortion based on an exponential function
% x - input
% gain - amount of distortion,
% mix - mix of original and distorted sound
%1=only distorted
gain = 11/5;
mix = 0.1;
q=x./abs(x);
y=q.*(1-exp(gain*(q.*x)));
y=mix*y+(1-mix)*x;
end

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!