Merge branch 'estevan' into main

This commit is contained in:
Estevan BIAU-LOYER 2023-03-29 22:50:42 +02:00
commit 7ecd9426db
23 changed files with 250 additions and 1 deletions

BIN
FIR.wav Normal file

Binary file not shown.

BIN
butter.wav Normal file

Binary file not shown.

18
buttering.m Normal file
View File

@ -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);

BIN
carrier22.wav Normal file

Binary file not shown.

37
chanvocoder.m Normal file
View File

@ -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

BIN
decimated.wav Normal file

Binary file not shown.

14
decimato.m Normal file
View File

@ -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);

BIN
down.wav Normal file

Binary file not shown.

15
downsampl.m Normal file
View File

@ -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);

19
fir.m Normal file
View File

@ -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);

21
last.m Normal file
View File

@ -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);

40
ouaiouai.m Normal file
View File

@ -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);

BIN
outfile.wav Normal file

Binary file not shown.

Binary file not shown.

BIN
output.wav Normal file

Binary file not shown.

0
recording Normal file
View File

BIN
recording.wav Normal file

Binary file not shown.

38
spectrogram.m Normal file
View File

@ -0,0 +1,38 @@
function spectrogram(signal, samplingFreq, step_size, window_size)
%%%%%%%%%%%%%%%%%%%%%%%
%function spectrogram(signal, samplingFreq, step_size, window_size)
% ex.: spectrogram(signal, samplingFreq, step_size, window_size)
%
% Task: Plot the spectrogram of a given signal
%
% Inputs:
% -signal: temporal signal to analyse
% -samplingFreq: sampling frequency of the temporal signal
% -step_size: how often the power spectrum will be computed in ms
% -window_size: size of the analysing window in ms
%
% Ouput: None
%
% author: Guillaume Gibert (guillaume.gibert@ecam.fr)
% date: 14/03/2023
%%%%%%%%%%%%%%%%%%%%%%%
figure;
subplot(2,1,1);
t=0:1/samplingFreq:length(signal)/samplingFreq-1/samplingFreq;
plot(t, signal');
xlim([0 length(signal)/samplingFreq-1/samplingFreq]);
ylabel('amplitude (norm. unit)');
subplot(2,1,2);
step = fix(step_size*samplingFreq/1000); % one spectral slice every step_size ms
window = fix(window_size*samplingFreq/1000); % window_size ms data window
fftn = 2^nextpow2(window); % next highest power of 2
[S, f, t] = specgram(signal, fftn, samplingFreq, window, window-step);
S = abs(S(2:fftn*4000/samplingFreq,:)); % magnitude in range 0<f<=4000 Hz.
S = S/max(S(:)); % normalize magnitude so that max is 0 dB.
S = max(S, 10^(-40/10)); % clip below -40 dB.
S = min(S, 10^(-3/10)); % clip above -3 dB.
imagesc (t, f, log(S)); % display in log scale
set (gca, "ydir", "normal"); % put the 'y' direction in the correct direction
xlabel('time (s)');
ylabel('frequency (Hz)');

View File

@ -3,6 +3,7 @@ pkg load signal
audiowrite('outmodulator22.wav',y,fs/2);
n = length(y);
t=0:1/fs:(n-1)/fs; % time range
<<<<<<< HEAD
figure;
plot(t,y);
xlabel('time (s)');
@ -12,3 +13,40 @@ ylabel('amplitude');
[power,duration]=frequencySpectrum(y, fs, false);
figure;
plot(duration,power);
=======
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);
>>>>>>> estevan

BIN
vocodedsound.wav Normal file

Binary file not shown.

9
vocoder.m Normal file
View File

@ -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)

BIN
white.wav Normal file

Binary file not shown.

BIN
white_periodic.wav Normal file

Binary file not shown.