last
This commit is contained in:
parent
e8766b03e3
commit
b3f68d5362
Binary file not shown.
|
|
@ -0,0 +1,18 @@
|
||||||
|
clear all
|
||||||
|
close all
|
||||||
|
pkg load signal
|
||||||
|
[y,fs] = audioread('modulator22.wav');
|
||||||
|
sound(y, fs);
|
||||||
|
n = length(y);
|
||||||
|
t=0:1/fs:(n-1)/fs; % time range
|
||||||
|
spectrogram(y,fs,5,30);
|
||||||
|
|
||||||
|
[y, fs] = audioread('modulator22.wav');
|
||||||
|
n = 8;
|
||||||
|
Wn = 0.0453;
|
||||||
|
[b, a] = butter(n, Wn);
|
||||||
|
|
||||||
|
y = filter(b, a, y);
|
||||||
|
spectrogram(y,fs,5,30);
|
||||||
|
sound(y, fs);
|
||||||
|
audiowrite('butter.wav',y,fs);
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,37 @@
|
||||||
|
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.
|
|
@ -0,0 +1,14 @@
|
||||||
|
clear all
|
||||||
|
close all
|
||||||
|
pkg load signal
|
||||||
|
[x, fs] = audioread('modulator22.wav');
|
||||||
|
sound(x, fs);
|
||||||
|
y = decimate(x, 5);
|
||||||
|
new_fs = fs/5;
|
||||||
|
display(new_fs);
|
||||||
|
audiowrite('decimated.wav', y, new_fs);
|
||||||
|
spectrogram(x,fs,5,30);
|
||||||
|
title('original');
|
||||||
|
spectrogram(y,fs,5,30);
|
||||||
|
title('decimato');
|
||||||
|
sound(y, new_fs);
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
clear all
|
||||||
|
close all
|
||||||
|
pkg load signal
|
||||||
|
[x, fs] = audioread('butter.wav');
|
||||||
|
sound(x, fs);
|
||||||
|
new_fs = fs/5;
|
||||||
|
display(new_fs);
|
||||||
|
r = fs/new_fs;
|
||||||
|
y = downsample(x, r);
|
||||||
|
audiowrite('down.wav', y, new_fs);
|
||||||
|
spectrogram(x,fs,5,30);
|
||||||
|
title('original');
|
||||||
|
spectrogram(y,fs,5,30);
|
||||||
|
title('dowsampled');
|
||||||
|
sound(y, new_fs);
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
clear all
|
|
||||||
close all
|
|
||||||
pkg load signal
|
|
||||||
[y,fs] = audioread('modulator22.wav');
|
|
||||||
audiowrite('outmodulator22.wav',y,fs/2);
|
|
||||||
n = length(y);
|
|
||||||
t=0:1/fs:(n-1)/fs; % time range
|
|
||||||
downsample(y,4000);
|
|
||||||
spectrogram(y,fs,5,30);
|
|
||||||
[power,duration]=frequencySpectrum(y, fs, false);
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
clear all
|
||||||
|
close all
|
||||||
|
pkg load signal
|
||||||
|
[y,fs] = audioread('modulator22.wav');
|
||||||
|
sound(y, fs);
|
||||||
|
n = length(y);
|
||||||
|
t=0:1/fs:(n-1)/fs; % time range
|
||||||
|
spectrogram(y,fs,5,30);
|
||||||
|
|
||||||
|
[y, fs] = audioread('modulator22.wav');
|
||||||
|
n = 30;
|
||||||
|
fc = 1000/(fs/2);
|
||||||
|
w = hamming(n+1);
|
||||||
|
b = fir1(n, fc, w);
|
||||||
|
filtered_signal = filter(b, 1, y);
|
||||||
|
spectrogram(filtered_signal,fs,5,30);
|
||||||
|
sound(filtered_signal, fs);
|
||||||
|
audiowrite('FIR.wav',filtered_signal,fs);
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
pkg load signal
|
||||||
|
|
||||||
|
[x, fs] = audioread('carrier22.wav');
|
||||||
|
recording_duration = 5; % in seconds % in Hz
|
||||||
|
|
||||||
|
|
||||||
|
printf('Start recording...\n');
|
||||||
|
recording = record(5, 22400);
|
||||||
|
printf('Recording finished.\n');
|
||||||
|
audiowrite('recording.wav', recording, fs);
|
||||||
|
plot(recording);
|
||||||
|
recording1= 'recording.wav';
|
||||||
|
carrierfile = 'carrier22.wav';
|
||||||
|
outfile = 'vocodedsound.wav';
|
||||||
|
|
||||||
|
[modul, sr1] = audioread(recording1);
|
||||||
|
[carrier, sr2] = audioread(carrierfile);
|
||||||
|
if sr2 ~= fs, disp('your sampling rates dont match'); end
|
||||||
|
|
||||||
|
y = chanvocoder(carrier, modul, 512, 16, 0.2);
|
||||||
|
audiowrite('outfile.wav', y, sr1);
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
pkg load signal
|
||||||
|
[y,fs] = audioread('modulator22.wav');
|
||||||
|
audiowrite('outmodulator22.wav',y,fs/2);
|
||||||
|
n = length(y);
|
||||||
|
t=0:1/fs:(n-1)/fs; % time range
|
||||||
|
i=1;
|
||||||
|
ldft=[];
|
||||||
|
while (i<6)
|
||||||
|
[power,duration]=frequencySpectrum(y, fs, false);
|
||||||
|
disp(i);
|
||||||
|
disp (duration);
|
||||||
|
ldft(i)=duration;
|
||||||
|
i=i+1;
|
||||||
|
end
|
||||||
|
disp (ldft);
|
||||||
|
lfft=[];
|
||||||
|
i=1;
|
||||||
|
while (i<6)
|
||||||
|
[power,duration]=frequencySpectrum(y, fs, true);
|
||||||
|
disp(i);
|
||||||
|
disp (duration);
|
||||||
|
lfft(i)=duration;
|
||||||
|
i=i+1;
|
||||||
|
end
|
||||||
|
disp (lfft);
|
||||||
|
i=1;
|
||||||
|
ratio=[];
|
||||||
|
while (i<6)
|
||||||
|
ratio(i)=(lfft(i))/(ldft(i));
|
||||||
|
i=i+1;
|
||||||
|
end
|
||||||
|
disp('ratio');
|
||||||
|
disp(ratio);
|
||||||
|
avgratio=mean(ratio);
|
||||||
|
disp('avgratio');
|
||||||
|
disp(avgratio);
|
||||||
|
|
||||||
|
stdratio= std(ratio);
|
||||||
|
disp('stdratio');
|
||||||
|
disp(stdratio);
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,11 +0,0 @@
|
||||||
clear all
|
|
||||||
close all
|
|
||||||
pkg load signal
|
|
||||||
[y,fs] = audioread('modulator22.wav');
|
|
||||||
audiowrite('outmodulator22.wav',y,fs/2);
|
|
||||||
n = length(y);
|
|
||||||
t=0:1/fs:(n-1)/fs; % time range
|
|
||||||
spectrogram(y,fs,5,30);
|
|
||||||
y=y(floor(0.7*fs):floor(1.15*fs));
|
|
||||||
[power,duration]=frequencySpectrum(y, fs, false);
|
|
||||||
spectrogram(y,fs,5,30);
|
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,9 @@
|
||||||
|
pkg load signal
|
||||||
|
modfile = 'modulator22.wav';
|
||||||
|
carfile = 'carrier22.wav';
|
||||||
|
outfile = 'vocodedsound.wav'
|
||||||
|
[modul, sr1] = audioread(modfile);
|
||||||
|
[carrier, sr2] = audioread(carfile);
|
||||||
|
if sr1~=sr2, disp('your sampling rates dont match'); end
|
||||||
|
y = chanvocoder(carrier, modul, 512, 16, .2);
|
||||||
|
audiowrite('outfile.wav',y,sr1)
|
||||||
Binary file not shown.
Loading…
Reference in New Issue