D
DeletedUser
Guest
I'm a retired DSP software design engineer. I want to continue my previous activities from time to time. I have been working on several projects with the Arduino Nano, UNO. I just bought a Teensy 4.0 board and audio shield. I want to start a new project as soon as I receive the headers for the shield.
I've studied the Teensy GUI Audio Design Tool which looks very useful for open-loop algorithms. However, I would like to create an Automatic Gain Control for my TV or mp3 player so that I won't need to continuously push the +- remote control button every time a louder commercial interrupts the film or my next mp3 song was recorded at a different volume level.
Basically, my question concerns, how can I write a Teensy AGC audio function (non-optimized at first). Below, I am providing a Matlab code for the details. Thanks.
---------------------------------------------- Matlab Code ----------------------------------
clear;
close all;
filename='Baez.wav';
filename=input('input wav filename: ','s');
[sig, fs]=audioread(filename);
T=1/fs;
[nsamp,dummy]=size(sig);
fclose('all');
k=.00001;
ref=.07;
gain(1)=0.5;
numiter=nsamp;
for iter=1:numiter
sigout(iter)=sig(iter)*gain(iter);
t(iter)=(iter-1)*T;
err(iter)=abs(sigout(iter))-ref;
gain(iter+1)=gain(iter)-err(iter)*k;
end
figure
plot(t,sig,'b');
grid on;
zoom on;
hold on;
plot(t,sigout,'r');
hold off;
title('Input Signal(blue), Output Signal(red)');
xlabel('seconds');
I've studied the Teensy GUI Audio Design Tool which looks very useful for open-loop algorithms. However, I would like to create an Automatic Gain Control for my TV or mp3 player so that I won't need to continuously push the +- remote control button every time a louder commercial interrupts the film or my next mp3 song was recorded at a different volume level.
Basically, my question concerns, how can I write a Teensy AGC audio function (non-optimized at first). Below, I am providing a Matlab code for the details. Thanks.
---------------------------------------------- Matlab Code ----------------------------------
clear;
close all;
filename='Baez.wav';
filename=input('input wav filename: ','s');
[sig, fs]=audioread(filename);
T=1/fs;
[nsamp,dummy]=size(sig);
fclose('all');
k=.00001;
ref=.07;
gain(1)=0.5;
numiter=nsamp;
for iter=1:numiter
sigout(iter)=sig(iter)*gain(iter);
t(iter)=(iter-1)*T;
err(iter)=abs(sigout(iter))-ref;
gain(iter+1)=gain(iter)-err(iter)*k;
end
figure
plot(t,sig,'b');
grid on;
zoom on;
hold on;
plot(t,sigout,'r');
hold off;
title('Input Signal(blue), Output Signal(red)');
xlabel('seconds');