diff --git a/Capture/Butt_filter.PNG b/Capture/Butt_filter.PNG new file mode 100644 index 0000000..2b9ef6d Binary files /dev/null and b/Capture/Butt_filter.PNG differ diff --git a/Capture/Butt_plot.PNG b/Capture/Butt_plot.PNG new file mode 100644 index 0000000..7493ae8 Binary files /dev/null and b/Capture/Butt_plot.PNG differ diff --git a/Capture/Deci_plot.PNG b/Capture/Deci_plot.PNG new file mode 100644 index 0000000..0548052 Binary files /dev/null and b/Capture/Deci_plot.PNG differ diff --git a/Capture/Dow_FIR_plot.PNG b/Capture/Dow_FIR_plot.PNG new file mode 100644 index 0000000..085ee98 Binary files /dev/null and b/Capture/Dow_FIR_plot.PNG differ diff --git a/Capture/Down_butt_plot.PNG b/Capture/Down_butt_plot.PNG new file mode 100644 index 0000000..a34156c Binary files /dev/null and b/Capture/Down_butt_plot.PNG differ diff --git a/Capture/Down_plot.PNG b/Capture/Down_plot.PNG new file mode 100644 index 0000000..af4138a Binary files /dev/null and b/Capture/Down_plot.PNG differ diff --git a/Capture/FIR_filter.PNG b/Capture/FIR_filter.PNG new file mode 100644 index 0000000..f0f4c29 Binary files /dev/null and b/Capture/FIR_filter.PNG differ diff --git a/Capture/FIR_plot.PNG b/Capture/FIR_plot.PNG new file mode 100644 index 0000000..3a997c6 Binary files /dev/null and b/Capture/FIR_plot.PNG differ diff --git a/Capture/Sound_plot.PNG b/Capture/Sound_plot.PNG new file mode 100644 index 0000000..4b367b2 Binary files /dev/null and b/Capture/Sound_plot.PNG differ diff --git a/FT_times.m b/FT_times.m new file mode 100644 index 0000000..46402f4 --- /dev/null +++ b/FT_times.m @@ -0,0 +1,21 @@ +clear all +close all +clc + +[y, fs] = audioread("sound/modulator22.wav"); +times = []; +item_num = 20; +for j = 1:item_num + localtime = []; + for i = 0:1 + t0 = clock (); + frequencySpectrum_noplot(y, fs, 0); %true does FFT, false DFT + localtime(i+1) = etime (clock (), t0); + endfor + times = [times; localtime]; +endfor + +printf('Average DFT time: %d \n', mean(times(1:item_num, 1))) +printf('Standard deviation of DFT time: %d \n', std(times(1:item_num, 1))) +printf('Average FFT time: %d \n', mean(times(1:item_num, 2))) +printf('Standard deviation of FFT time: %d \n', std(times(1:item_num, 2))) \ No newline at end of file diff --git a/downsample_analysis.m b/downsample_analysis.m new file mode 100644 index 0000000..29f03ca --- /dev/null +++ b/downsample_analysis.m @@ -0,0 +1,114 @@ +clear all +close all +clc + +% Modify the desired frequency for the whole code here +desired_freq = 4000; +% Read and Set up coeficient +[y, fs] = audioread("sound/modulator22.wav"); +decrease_coef = round(fs/desired_freq); + +% Modify Signal with downsample +% Only keeps one sample out of decrease_coef +down_y = downsample(y,decrease_coef); +down_fs = fs/decrease_coef; +audiowrite("sound/down_output.wav", down_y, down_fs); +% Plot Down Modified +plot(0:1/down_fs:(length(down_y)-1)/down_fs,down_y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("Downsample Sound Amplitude Over Time"); + +% Modify Signal with decimate +% Only keeps one sample out of decrease_coef +deci_y = decimate(y,decrease_coef); +deci_fs = fs/decrease_coef; +audiowrite("sound/deci_output.wav", deci_y, deci_fs); +% Plot Down Modified +figure; +plot(0:1/deci_fs:(length(deci_y)-1)/deci_fs,deci_y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("Decimate Sound Amplitude Over Time"); + + +% Filter Signal with FIR filter +order = 30; +cutoff_freq = 1000; % in Hz +fir_b = fir1(order, cutoff_freq/(fs/2)); +% Show Filter +figure +freqz(fir_b) +% Apply filter +fir_y = filter(fir_b, 1, y); +audiowrite("sound/fir_output.wav", fir_y, fs); +% Plot Down Modified +figure; +plot(0:1/fs:(length(fir_y)-1)/fs,fir_y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("FIR Filter Sound Amplitude Over Time"); + +% Filter Signal with Butter filter +order = 8; +cutoff_freq = 1000; % in Hz +[b, a] = butter(order, cutoff_freq/(fs/2), 'low'); +% Show Filter +figure +freqz(b) +% Apply filter +butt_y = filter(b, a, y); +audiowrite("sound/butt_output.wav", butt_y, fs); +% Plot Down Modified +figure; +plot(0:1/fs:(length(butt_y)-1)/fs,butt_y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("Butter Filter Sound Amplitude Over Time"); + +% Test FIR Filter Stability +% Find the transfer function +H = tf(fir_b, 1); +% Get the poles of the transfer function +poles = pole(H); +% Check if all poles are inside the unit circle +if all(abs(poles) < 1) + disp('The FIR filter is stable'); +else + disp('The FIR filter is unstable'); +end +% Test Butter Filter Stability +% Find the transfer function +H = tf(b, a); +% Get the poles of the transfer function +poles = pole(H); +% Check if all poles are inside the unit circle +if all(abs(poles) < 1) + disp('The Butter filter is stable'); +else + disp('The Butter filter is unstable'); +end + +% Modify Signal with downsample +% Only keeps one sample out of decrease_coef +down_fir_y = downsample(fir_y,decrease_coef); +down_fir_fs = fs/decrease_coef; +audiowrite("sound/down_fir_output.wav", down_fir_y, down_fir_fs); +% Plot Down Modified +figure +plot(0:1/down_fir_fs:(length(down_fir_y)-1)/down_fir_fs,down_fir_y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("Downsample FIR Sound Amplitude Over Time"); + +% Modify Signal with downsample +% Only keeps one sample out of decrease_coef +down_butt_y = downsample(butt_y,decrease_coef); +down_butt_fs = fs/decrease_coef; +audiowrite("sound/down_butt_output.wav", down_butt_y, down_butt_fs); +% Plot Down Modified +figure +plot(0:1/down_butt_fs:(length(down_butt_y)-1)/down_butt_fs,down_butt_y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("Downsample Butter Sound Amplitude Over Time"); \ No newline at end of file diff --git a/frequencySpectrum_noplot.m b/frequencySpectrum_noplot.m new file mode 100644 index 0000000..fc4cd51 --- /dev/null +++ b/frequencySpectrum_noplot.m @@ -0,0 +1,44 @@ +function [power, duration] = frequencySpectrum_noplot(signal, fs, pad) +%%%%%%%%%%%%%%%%%% +%function power = frequencySpectrum(signal, fs, pad) +% +% Task: Display the power spectrum (lin and log scale) of a given signal +% +% Input: +% - signal: the input signal to process +% - fs: the sampling rate +% -pad: boolean if true, signal is padded with 0 to the next power of 2 -> FFT instead of DFT +% +% Output: +% - power: the power spectrum +% +% +% Guillaume Gibert, guillaume.gibert@ecam.fr +% 25/04/2022 +%%%%%%%%%%%%%%%%%% + +n = length(signal); % number of samples + +if (pad) + n = 2^nextpow2(n); +end + +tic +y = fft(signal, n);% compute DFT of input signal +duration = toc; + +power = abs(y).^2/n; % power of the DFT + +[val, ind] = max(power); % find the mx value of DFT and its index + +t=0:1/fs:(n-1)/fs; % time range +%pad signal with zeros +if (pad) + signal = [ signal; zeros( n-length(signal), 1)]; +end + +f = (0:n-1)*(fs/n); % frequency range + + + + diff --git a/one.png b/one.png new file mode 100644 index 0000000..26d8d04 Binary files /dev/null and b/one.png differ diff --git a/sound/butt_output.wav b/sound/butt_output.wav new file mode 100644 index 0000000..b22fe50 Binary files /dev/null and b/sound/butt_output.wav differ diff --git a/sound/carrier22.wav b/sound/carrier22.wav new file mode 100644 index 0000000..8b2526c Binary files /dev/null and b/sound/carrier22.wav differ diff --git a/sound/deci_output.wav b/sound/deci_output.wav new file mode 100644 index 0000000..7196220 Binary files /dev/null and b/sound/deci_output.wav differ diff --git a/sound/desktop.ini b/sound/desktop.ini new file mode 100644 index 0000000..2c8b98e --- /dev/null +++ b/sound/desktop.ini @@ -0,0 +1,2 @@ +[.ShellClassInfo] +IconResource=C:\Program Files\Google\Drive File Stream\72.0.3.0\GoogleDriveFS.exe,23 diff --git a/sound/down_butt_output.wav b/sound/down_butt_output.wav new file mode 100644 index 0000000..cb9ecd0 Binary files /dev/null and b/sound/down_butt_output.wav differ diff --git a/sound/down_fir_output.wav b/sound/down_fir_output.wav new file mode 100644 index 0000000..cad8efc Binary files /dev/null and b/sound/down_fir_output.wav differ diff --git a/sound/down_output.wav b/sound/down_output.wav new file mode 100644 index 0000000..0fa38ee Binary files /dev/null and b/sound/down_output.wav differ diff --git a/sound/fir_output.wav b/sound/fir_output.wav new file mode 100644 index 0000000..e9c4f27 Binary files /dev/null and b/sound/fir_output.wav differ diff --git a/sound/modulator22.wav b/sound/modulator22.wav new file mode 100644 index 0000000..a6ad482 Binary files /dev/null and b/sound/modulator22.wav differ diff --git a/sound/output.wav b/sound/output.wav new file mode 100644 index 0000000..ce603f2 Binary files /dev/null and b/sound/output.wav differ diff --git a/sound/white.wav b/sound/white.wav new file mode 100644 index 0000000..98c77ea Binary files /dev/null and b/sound/white.wav differ diff --git a/sound/white_periodic.wav b/sound/white_periodic.wav new file mode 100644 index 0000000..f24def4 Binary files /dev/null and b/sound/white_periodic.wav differ diff --git a/spectral_analysis.m b/spectral_analysis.m new file mode 100644 index 0000000..926f076 --- /dev/null +++ b/spectral_analysis.m @@ -0,0 +1,51 @@ +clear all +close all +clc + +[y, fs] = audioread("sound/modulator22.wav"); +ranges = [17000, 21000; 30500, 36000; 41500, 46000]; +one = y(ranges(1,1):ranges(1,2)); +two = y(ranges(2,1):ranges(2,2)); +three = y(ranges(3,1):ranges(3,2)); + +word = three; + +n = length(word); +f = (0:n-1)*(fs/n); +f1 = 0;%Hz +f2 = 2500;%Hz +idx = find(f >= f1 & f <= f2); %define the index of the freq range +f = f(idx); +y = fft(word, n);% compute DFT of input signal +power = abs(y).^2/n; +power = power(idx);%limit the signal to the frequency ROI +[val, ind] = max(power); + +%lowpass for the formant, moving average + +for j = 1:length(idx) + tot = 0; + for k = j-18:j + if k <=0 + tot = tot + power(1); + else + tot = tot + power(k); + endif + endfor + power_avg(j) = 1/6*(tot); +endfor + +figure; + +subplot(1,2,1) % time plot +plot(0:1/fs:(length(word)-1)/fs,word); +xlabel('Time (s)'); +ylabel('Amplitude (a.u.)'); + +subplot(1,2,2) % freq range plot +plot(f,10*log10(power/power(ind))); hold on; +plot(f, 10*log10(power_avg/power(ind)), 'r'); +xlabel('Frequency (Hz)') +ylabel('Power (dB)') + + diff --git a/spectrogram_analysis.m b/spectrogram_analysis.m new file mode 100644 index 0000000..8d0ba45 --- /dev/null +++ b/spectrogram_analysis.m @@ -0,0 +1,8 @@ +clear all +close all +clc + +[y, fs] = audioread("sound/modulator22.wav"); +step_size = 5; %ms +window_size = 30;%ms, ideal value 25 +spectrogram(y, fs, step_size, window_size) \ No newline at end of file diff --git a/speech_analysis.m b/speech_analysis.m new file mode 100644 index 0000000..a879c5e --- /dev/null +++ b/speech_analysis.m @@ -0,0 +1,11 @@ +clear all +close all +clc + +[y, fs] = audioread("sound/modulator22.wav"); +plot(0:1/fs:(length(y)-1)/fs,y); +xlabel("Time (s)"); +ylabel("Amplitude"); +title("Sound Amplitude Over Time"); + +audiowrite("sound/output.wav", y, fs/2); \ No newline at end of file diff --git a/three.png b/three.png new file mode 100644 index 0000000..316d8e6 Binary files /dev/null and b/three.png differ diff --git a/two.png b/two.png new file mode 100644 index 0000000..ae5e38a Binary files /dev/null and b/two.png differ