arraysmatlabfilteringsignal-processingbandpass-filter

Filtering of fourier transforms of audio signals


I have an array containing the Fourier transform of an input audio signal (the amplitudes corresponding to various frequencies). I wish to select specific ranges of the signal without using the inbuilt functions. I have performed the following simple operations for the same :

[audio_in,audio_freq_sampl]=audioread('F:\Signals and Systems\Take Me Home Country Roads (John Denver Cover).wav');
Length_audio=length(audio_in);
df=audio_freq_sampl/Length_audio;
frequency_audio=-audio_freq_sampl/2:df:audio_freq_sampl/2-df;
figure
FFT_audio_in=fft(audio_in);

n = length(FFT_audio_in);
init = 30000;
fin = 40000;  
conji= mod((n-init+2),n) ;
conjf= mod((n-fin+2),n) ;
fs_1(1:n) = 0.0 ;
fs_1(init:fin) = FFT_audio_in(init:fin);
fs_1(conji:conjf) = FFT_audio_in(conji:conjf);

plot(frequency_audio,abs(fs_1));

enter image description here

As we can see here, there is only one peak. the other one should be visible at the other end of the plot in the range.

The song can be found here - https://www.youtube.com/watch?v=WF046Z5tPJE

The song must be converted to a .wav file before reading it.

The above code should give me a plot containing two small peaks corresponding to the ranges of frequencies - (init , fin) and (conji , conjf). However, I am getting a peak only corresponding to the 1st range. Both these ranges are within the size of the array - FFT_audio_in.


Solution

  • The error lies in the following lines of code :

    n = length(FFT_audio_in);
    init = 30000;
    fin = 40000;  
    conji= mod((n-init+2),n) ;
    conjf= mod((n-fin+2),n) ;
    fs_1(1:n) = 0.0 ;
    fs_1(init:fin) = FFT_audio_in(init:fin);
    fs_1(conji:conjf) = FFT_audio_in(conji:conjf);
    

    Turns out that in the above lines of code, conji < conjf. So in the last line of the code, I am spanning through the vector with the initial point being larger than the final point. However, with the following lines of code, this issue is resolved :

    n = length(FFT_audio_in);
    init = n/4;
    fin = n/4 + 10000;  
    conji= mod((n-init+2),n) ;
    conjf= mod((n-fin+2),n) ;
    init_2 = min(conji , conjf);
    fin_2 = max(conji , conjf);
    fs_1(1:n) = 0.0 ;
    fs_1(init:fin) = FFT_audio_in(init:fin);
    fs_1(init_2:fin_2) = FFT_audio_in(init_2:fin_2);