How do I read and split an audio file into four different frequency ranges?

I have an audio file of sampling frequency as 16 kHz. Now I would like to read it and split its samples into four range. Namely:
0 kHz - 1 kHz
1 kHz - 2 kHz
2 kHz - 4 kHz
4 kHz - 8 kHz
I have come about the following code but I am not sure if it is correct? I wanted to know if there is any other way.
[signal,fs]=audioread('003.wav');
SigFD = (signal);
n = length(signal); % number of samples
deltaF = fs/n; % frequency resolution
F = [0:floor(n/2)-1, -(floor(n/2)):-1]*deltaF; % frequency vector
lowF = 0; % lowF and highF defines one of the range
highF = 1000;
part1Range = abs(F)>lowF&abs(F)<highF;
Fpart1 = F(part1Range);
Sig1FD = SigFD(part1Range);

 Accepted Answer

If you have R2018a or later, use the bandpass (link) function on your original signal, each with different passband limits.
If you have an earlier version, use ellipord (link) and ellip (link), that together are almost as easy.

7 Comments

I could not understand this. Could you please help explain using some pseudo code.
Thank You
I wrote the following code. Not sure if its correct
[signal,fs]=audioread('003.wav');
SigFD = (signal);
n = length(signal); % number of samples
deltaF = fs/n; % frequency resolution
F = [0:floor(n/2)-1, -(floor(n/2)):-1]*deltaF; % frequency vector
% lowF = 0;
% highF = 1000;
f0=0;
f1=1000;
f2=2000;
f4=4000;
f8=8000;
part1Range = abs(F)>f0&abs(F)<f1;
part2Range = abs(F)>f1&abs(F)<f2;
part3Range = abs(F)>f2&abs(F)<f4;
part4Range = abs(F)>f4&abs(F)<f8;
Fpart1 = F(part1Range);
Sig1FD = SigFD(part1Range);
Fpart2 = F(part2Range);
Sig2FD = SigFD(part2Range);
Fpart3 = F(part3Range);
Sig3FD = SigFD(part3Range);
Fpart4 = F(part4Range);
Sig4FD = SigFD(part4Range);
I cannot follow what your code is doing.
I was thinking of something like this:
[signal,Fs]=audioread('003.wav');
y{1} = bandpass(signal,[0.1 1E+3],Fs);
y{2} = bandpass(signal,[1E+3 2E+3],Fs);
y{3} = bandpass(signal,[2E+3 4E+3],Fs);
y{4} = bandpass(signal,[4E+3 8E+3],Fs);
Experiment to get the result you want.
One thing is bothering me is when I check the max value of signal it says 0.98 but the max value of this y{1} is 45.
I think that y{1}, y{2} etc should contain the same values as in "signal" but with a smaller dimension. y{1}, y{2}, y{3}, y{4} should actually be a subset of "signal". Isn't it? Please correct me if I a wrong
Not necessarily.
‘I think that y{1}, y{2} etc should contain the same values as in "signal" but with a smaller dimension’ ...
Different bands of signal may easily have different energies and amplitudes. Consider a 1.5 kHz pure tone. It will have an amplitude of 1 for ‘y{2}’ and essentially zero elsewhere.
Could you please suggest how to do it MATLAB 2015 using ellipord?
Thank You
As always, my pleasure.
The first filter is a simple lowpass filter with a passband a 1 kHz. You can use this prototype code to design it.
This designs the second filter:
Fs = 1.6E+4; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Fnotch = 1.5E3; % Notch Frequency (Hz)
BW = 1E+3; % Passband Width (Hz)
Ws = [Fnotch-BW/2-1 Fnotch+BW/2+1]/Fn; % Passband Frequency Vector (Normalised)
Wp = [Fnotch-BW/2-5 Fnotch+BW/2+5]/Fn; % Stopband Frequency Vector (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Attenuation (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Default Here Is A Bandpass Filter
[z,p,k] = ellip(n,Rp,Rs,Wp);
[sos,g] = zp2sos(z,p,k); % Use Second-Order-Section Implementation For Stability
% s_filtered = filtfilt(sos,g,s); % Filter Signal (Here: ‘s’)
figure
freqz(sos, 2^14, Fs) % Bode Plot Of Filter
set(subplot(2,1,1), 'XLim',[0 Fn]) % Optional, Change Limits As Necessary For Best Resolution
set(subplot(2,1,2), 'XLim',[0 Fn]) % Optional, Change Limits As Necessary For Best Resolution
The others are the same except for the centre frequencies and the bandwidths.

Sign in to comment.

More Answers (0)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!