|
Variable filtering. In this filtering method, the frequency spectrum is separated in a log4 fashion, where fs = sampling rate, frequency = 44160, and n = sample length.
Freq samples Method 1 Method 2
0-20 0 - 20n/fs remove all remove all 20-80 20n/fs+1 - 80n/fs remove none remove none 80-320 80n/fs+1 - 320n/fs 1/2 1/5 320-1280 320n/fs+1 - 1280n/fs 2/3 2/5 1280-5120 1280n/fs+1 - 5120n/fs 3/4 3/4 5120-20000 5120n/fs+1 - 20000n/fs 4/5 4/5 20000-fs/2 20000n/fs+1 - n/2 remove all remove all
Thus, in method 1, we remove half the samples in the frequency range from 81 to 320 hertz, two out of three samples from 312 to 1280 Hertz, etc. etc. Method 2 has a constant denominator of 5. The functions below will implement this compression, where fs = sampling rate, frequency = 44160 and L is the ffted signal (note, if memory is a problem, use a 2^17 or 2^16 signal).
function removefreq(fs, L, method)
n=length(L); sampleHi=[80*n/fs;320*n/fs;1280*n/fs;5120*n/fs;20000*n/fs]; sampleLo=[20n/fs+1;80*n/fs+1;320*n/fs+1;1280*n/fs+1;5120*n/fs+1]; If method=1 Fracnum=[1;2;3;4]; %% Fraction numerators for Method 1 Fracden=[2;3;4;5]; %% Fraction denominators for Method 1 end If method=2 Fracnum=[1;2;3;4]; %% Fraction numerators for Method 2 Fracden=[5;5;5;5]; %% Fraction denominators for Method 2 end for i=1:4 for n=1:Fracnum(i) for q=1:int((sampleHi(i)-sampleLo(i))/Fracden(i)) L(sampleLo(i)+n+q*Fracden(i))=0; end end end L(n/2:n+1)=fliplr(L(1:n/2));
%% This last step takes the first half of the frequency spectrum and flips it %% placing it on the last half. If the frequency spectrum is symmetric along %% fs/2, then this should work.
And a beta finished program...
%% note, input = 'filename1.wav' and output = 'filename2.wav'
function compression(input, output, signalstart, signalend, method) %% make sure n = signalend - signalstart = power of 2 [[l,r],fs,nbits] = wavread(wavfile,[signalstart signalend]; n = signalend - signalstart l = fft(l,n); r = fft(r,n); sampleHi = [80*n/fs;320*n/fs;1280*n/fs;5120*n/fs;20000*n/fs]; sampleLo = [20n/fs+1;80*n/fs+1;320*n/fs+1;1280*n/fs+1;5120*n/fs+1]; If method = 1 Fracnum = [1;2;3;4]; Fracden=[2;3;4;5]; end If method=2 Fracnum=[1;2;3;4]; Fracden=[5;5;5;5]; end for i=1:4 for n=1:Fracnum(i) for q=1:int((sampleHi(i)-sampleLo(i))/Fracden(i)) l(sampleLo(i)+n+q*Fracden(i))=0; end end end l(n/2:n+1)=fliplr(l(1:n/2)); for i=1:4 for n=1:Fracnum(i) for q=1:int((sampleHi(i)-sampleLo(i))/Fracden(i)) r(sampleLo(i)+n+q*Fracden(i))=0; end end end r(n/2:n+1)=fliplr(r(1:n/2)); l=ifft(l,n); r=ifft(r,n);
soundsc([l,r],fs,nbits)
|
|