The problem was that the Vin (pin 2) of this IC was grounded, thus the output renders only the positive part of the signal.
Instead of this:
I had then 2 solutions:
1. Either I could modify the hardware to input into the Vin a Vcc/2 voltage.
2. Or I could deal with the distortion via software.
To see if I could restore the signal I analysed its spectrum of the distorted signal:
And I had to restore it to look like this:
For such a simple signal a simple low pass filter would do. But I realized that it would be impossible for more complex signals.
Here is the Matlab/Octave code that I used to generate the plots above:
Fs = 44100;
time = linspace(0, 1, Fs + 1);
sine = sin(2 * pi * 440 * time);
plot(time, sine);
figure;
player = audioplayer(sine, 44100);
play(player);
positiveOnly = (sine + abs(sine)) / 2;
plot(time, positiveOnly);
figure;
player = audioplayer(positiveOnly, Fs);
play(player);
sineSpectre = fft(sine);
plot(time, sineSpectre);
figure;
positiveOnlySpectre = fft(positiveOnly);
plot(time, positiveOnlySpectre);
No comments:
Post a Comment