diff --git a/Code/frequencySpectrum_old.m b/Code/frequencySpectrum_old.m new file mode 100644 index 0000000..bb2512b --- /dev/null +++ b/Code/frequencySpectrum_old.m @@ -0,0 +1,62 @@ +function [power, duration] = frequencySpectrum(signal, fs, pad, plot) +%%%%%%%%%%%%%%%%%% +%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 + +if (plot) + % plots + figure; + + subplot(1,3,1) % time plot + t=0:1/fs:(n-1)/fs; % time range + %pad signal with zeros + if (pad) + signal = [ signal; zeros( n-length(signal), 1)]; + end + plot(t, signal) + xticks(0:0.1*fs:n*fs); + xticklabels(0:0.1:n/fs); + xlabel('Time (s)'); + ylabel('Amplitude (a.u.)'); + + subplot(1,3,2) % linear frequency plot + f = (0:n-1)*(fs/n); % frequency range + plot(f,power, 'b*'); hold on; + plot(f,power, 'r'); + xlabel('Frequency (Hz)') + ylabel('Power (a.u.)') + + subplot(1,3,3) % log frequency plot + plot(f,10*log10(power/power(ind))); + xlabel('Frequency (Hz)') + ylabel('Power (dB)') +end + diff --git a/Code/speech_analysis_complete_sampling_part.m b/Code/speech_analysis_complete_sampling_part.m index 3d14fcf..2087418 100644 --- a/Code/speech_analysis_complete_sampling_part.m +++ b/Code/speech_analysis_complete_sampling_part.m @@ -30,12 +30,12 @@ durations_fft = zeros(1, num_measurements); for i = 1:num_measurements % Measure time taken for DFT tic; - [power_dft, duration_dft] = frequencySpectrum(signal, Fs, false, false); + [power_dft, duration_dft] = frequencySpectrum_old(signal, Fs, false, false); durations_dft(i) = duration_dft; % Measure time taken for FFT with padding tic; - [power_fft, duration_fft] = frequencySpectrum(signal, Fs, true, false); + [power_fft, duration_fft] = frequencySpectrum_old(signal, Fs, true, false); durations_fft(i) = duration_fft; end diff --git a/Images/Screenshot 2024-03-25 at 09.10.50.png b/Images/Average duration and standard deviation DFT and FFT with padding.png similarity index 100% rename from Images/Screenshot 2024-03-25 at 09.10.50.png rename to Images/Average duration and standard deviation DFT and FFT with padding.png diff --git a/Images/Screenshot 2024-03-25 at 08.54.03.png b/Images/Display Signal vs Slowed Signal.png similarity index 100% rename from Images/Screenshot 2024-03-25 at 08.54.03.png rename to Images/Display Signal vs Slowed Signal.png diff --git a/Images/Screenshot 2024-03-25 at 09.24.47.png b/Images/Screenshot 2024-03-25 at 09.24.47.png deleted file mode 100644 index d940989..0000000 Binary files a/Images/Screenshot 2024-03-25 at 09.24.47.png and /dev/null differ diff --git a/Images/Screenshot 2024-03-25 at 10.47.06.png b/Images/Screenshot 2024-03-25 at 10.47.06.png deleted file mode 100644 index ca941ed..0000000 Binary files a/Images/Screenshot 2024-03-25 at 10.47.06.png and /dev/null differ diff --git a/Images/Screenshot 2024-03-25 at 10.49.01.png b/Images/Screenshot 2024-03-25 at 10.49.01.png deleted file mode 100644 index bebbd34..0000000 Binary files a/Images/Screenshot 2024-03-25 at 10.49.01.png and /dev/null differ diff --git a/Images/Screenshot 2024-03-25 at 09.26.53.png b/Images/spectrogram Slowed Signal vs Signal.png similarity index 100% rename from Images/Screenshot 2024-03-25 at 09.26.53.png rename to Images/spectrogram Slowed Signal vs Signal.png diff --git a/downsampled_signal2.wav b/downsampled_signal2.wav index ffd4e55..6dfbcb4 100644 Binary files a/downsampled_signal2.wav and b/downsampled_signal2.wav differ