MATLAB: Turning binary data into speaker output.

air gappingaudio-outputbinaryloudnessMATLABtranslation

Hi I'm trying to come up with a code that turns binary data into an audio loudness signal for a presentation on air gapping.
I'm not entirely sure how but I would like to do it simply using Matlab to send a distinct loudness change output over time to the computer's speaker. Basically like morse code.
Any white noise audio file can be used as a base. I will be using a recording of a computer fan.
I am aiming for the following translation with 1 second between each:
1 – 80 dB (at your discretion)
0 – 50 dB (at your discretion)
00000 would be 5 seconds of the file at 50 dB
11111 would be 5 seconds of the file at 80 dB
Text: I love MATLAB 🙂
Binary: 01001001 00100000 01101100 01101111 01110110 01100101 00100000 01001101 01000001 01010100 01001100 01000001 01000010 00100000 00111010 00101001

Best Answer

  • MATLAB cannot control the loudness of a sound. It can control the relative loudness, but not the absolute loudness. With Windows, you can make ActiveX calls to control the volume settings of your output device... but that cannot control the absolute loudness, just the electrical signal level being fed into your amplifier.
    80 dB compared to 50 dB is 1000 times louder. The audio systems typically are 16 bit, so for the 50 dB sound you would have to restrict your samples to the +/- 0.001 range while your 80 dB would be the whole +/- 1.0 range.
    [whitenoise, Fs] = audioread('WhiteNoiseSource.mp4');
    noise5 = ifft( fft(whitenoise), Fs*5 );
    n5L = length(noise5);
    Text = 'I love MATLAB :)';
    Binary = logical(reshape(dec2bin(Text, 8).', 1, []) - '0');
    RelVol = 0.001 * ones(size(Binary));
    RelVol(Binary) = 1;
    BL = length(RelVol);
    shaped_noise = repelem(RelVol, n5L) .* repelem(noise5, BL);
    sound(shaped_noise, Fs)