# How to shape the spectrum of an audio waveform?

6 views (last 30 days)
B. Madsen on 27 Aug 2015
Answered: Star Strider on 28 Aug 2015
Here's what I'm trying to do:
1. Read in an input audio waveform and a target spectrum.
2. Use a 30-band EQ (probably an array of Butterworth filters) to make the spectrum of the input waveform match the target.
3. Check that the spectrum of the newly shaped waveform matches the target within 2-3 dB in each frequency band and perform subsequent iterations of the preceding steps if necessary until this criterion is met.
4. Output the newly shaped waveform.
(1) and (4) are of course very straightforward. It's (2) and (3) that I need help with. I'm new to Matlab, so any tips on what functions make the most sense for me to use would be greatly appreciated. Thanks!

Star Strider on 28 Aug 2015
Some help with 2:
This is archive code that creates a bank of 16 Butterworth filters. The ‘sos’ and ‘g’ cell arrays define the various filters, each corresponding to a centre frequency in the ‘cf’ vector. I can’t find the Question this was an Answer to, so I’ve lost that documentation. (There should be an Answers Query Language documentation link to help with this, but there isn’t. I’ve requested it.)
The code plots the passbands in figure(2). Change it and experiment with it to get the results you want:
Fs = 8200; % Samping Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
pf = linspace(20,4000,17); % Passband Frequencies
cf = pf(1:end-1)+(pf(2)-pf(1))/2; % Centre Frequencies
for k1 = 1:length(cf)
[z(k1,:),p(k1,:),k(k1)] = butter(7, [pf(k1) pf(k1+1)]/Fn);
[sos{k1},g{k1}] = zp2sos(z(k1,:),p(k1,:),k(k1));
[h(k1,:),w(k1,:)] = freqz(sos{k1},512,Fs);
end
figure(1)
plot(w([1 16],:), abs(h([1 16],:)))
grid
% axis([0 0.2 ylim])
figure(2)
freqz(sos{1})
hold on
for k1 = 2:16
freqz(sos{k1})
end
hold off
My general filter design procedure is here.