final final
This commit is contained in:
parent
10a30542e0
commit
6170ac8315
Binary file not shown.
|
|
@ -0,0 +1,57 @@
|
|||
function y = chanvocoder(carrier, modul, chan, numband, overlap)
|
||||
% y = chanvocoder(carrier, modul, chan, numband, overlap)
|
||||
% The Channel Vocoder modulates the carrier signal with the modulation signal
|
||||
% chan = number of channels (e.g., 512)
|
||||
% numband = number of bands (<chan) (e.g., 32)
|
||||
% overlap = window overlap (e.g., 1/4)
|
||||
|
||||
if numband>chan
|
||||
error('# bands must be < # channels')
|
||||
end
|
||||
|
||||
[rc, cc] = size(carrier);
|
||||
if cc>rc
|
||||
carrier = carrier';
|
||||
end
|
||||
|
||||
[rm, cm] = size(modul);
|
||||
if cm>rm
|
||||
modul = modul';
|
||||
end
|
||||
|
||||
st = min(rc,cc); % stereo or mono?
|
||||
if st~= min(rm,cm)
|
||||
error('carrier and modulator must have same number of tracks');
|
||||
end
|
||||
|
||||
len = min(length(carrier),length(modul)); % find shortest length
|
||||
carrier = carrier(1:len,1:st); % shorten carrier if needed
|
||||
modul = modul(1:len,1:st); % shorten modulator if needed
|
||||
L = 2*chan; % window length/FFT length
|
||||
w = hanning(L);
|
||||
if st==2
|
||||
w=[w w];
|
||||
end % window/ stereo window
|
||||
|
||||
bands = 1:round(chan/numband):chan; % indices for frequency bands
|
||||
bands(end) = chan;
|
||||
y = zeros(len,st); % output vector
|
||||
|
||||
ii = 0;
|
||||
while ii*L*overlap+L <= len
|
||||
ind = round([1+ii*L*overlap:ii*L*overlap+L]);
|
||||
FFTmod = fft( modul(ind,:) .* w ); % window & take FFT of modulator
|
||||
FFTcar = fft( carrier(ind,:) .* w ); % window & take FFT of carrier
|
||||
syn = zeros(chan,st); % place for synthesized output
|
||||
for jj = 1:numband-1 % for each frequency band
|
||||
b = [bands(jj):bands(jj+1)-1]; % current band
|
||||
syn(b,:) = FFTcar(b,:)*diag(mean(abs(FFTmod(b,:))));
|
||||
end % take product of spectra
|
||||
midval = FFTmod(1+L/2,:).*FFTcar(1+L/2,:); % midpoint is special
|
||||
synfull = [syn; midval; flipud( conj( syn(2:end,:) ) );]; % + and - frequencies
|
||||
timsig = real( ifft(synfull) ); % invert back to time
|
||||
y(ind,:) = y(ind,:) + timsig; % add back into time waveform
|
||||
ii = ii+1;
|
||||
end
|
||||
y = 0.8*y/max(max(abs(y))); % normalize output
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,28 @@
|
|||
%Speech Processing
|
||||
pkg load signal
|
||||
|
||||
modfile = "modulator22.wav";
|
||||
carfile = "carrier22.wav";
|
||||
white = "white.wav";
|
||||
white_p = "white_periodic.wav";
|
||||
outfile = "vocodedsound.wav";
|
||||
[modul, sr1] = audioread(modfile);
|
||||
[carrier, sr2] = audioread(carfile);
|
||||
[carrier_w, sr2_w] = audioread(carfile);
|
||||
[carrier_wp, sr2_wp] = audioread(carfile);
|
||||
|
||||
if sr1 ~= sr2
|
||||
disp('Your sampling rates dont match');
|
||||
endif
|
||||
|
||||
y = chanvocoder(carrier,modul, 512, 32, .2);
|
||||
audiowrite("vocodedsound.wav", y, sr1);
|
||||
y_w = chanvocoder(carrier_w,modul, 512, 32, .2);
|
||||
audiowrite("vocodedsound_w.wav", y, sr1);
|
||||
y_wp = chanvocoder(carrier_wp,modul, 512, 32, .2);
|
||||
audiowrite("vocodedsound_wp.wav", y, sr1);
|
||||
|
||||
%spectogram
|
||||
frequencySpectrum(modul,sr1,1);
|
||||
frequencySpectrum(carrier,sr2,1);
|
||||
frequencySpectrum(y,sr1,1);
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue