Add frequencySpectrum_old working with speech_analysis_complete_sampling_part. Remove useless images and rename images

This commit is contained in:
Louis 2024-03-26 10:46:52 +01:00
parent a30c5dd115
commit 26ee55fd5c
9 changed files with 64 additions and 2 deletions

View File

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

View File

@ -30,12 +30,12 @@ durations_fft = zeros(1, num_measurements);
for i = 1:num_measurements for i = 1:num_measurements
% Measure time taken for DFT % Measure time taken for DFT
tic; 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; durations_dft(i) = duration_dft;
% Measure time taken for FFT with padding % Measure time taken for FFT with padding
tic; 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; durations_fft(i) = duration_fft;
end end

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 260 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 784 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

View File

Before

Width:  |  Height:  |  Size: 506 KiB

After

Width:  |  Height:  |  Size: 506 KiB

Binary file not shown.