spectrogram and FT times test
This commit is contained in:
parent
c157ef5bb7
commit
1fdcf8dfa3
|
|
@ -0,0 +1,19 @@
|
||||||
|
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('Average FFT time: %d \n', mean(times(1:item_num, 2)))
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BIN
sound/output.wav
BIN
sound/output.wav
Binary file not shown.
|
|
@ -0,0 +1,9 @@
|
||||||
|
clear all
|
||||||
|
close all
|
||||||
|
clc
|
||||||
|
|
||||||
|
[y, fs] = audioread("sound/modulator22.wav");
|
||||||
|
%frequencySpectrum(y, fs, 0); %true does FFT, false DFT
|
||||||
|
step_size = 5; %ms
|
||||||
|
window_size = 30;%ms
|
||||||
|
spectrogram(y, fs, step_size, window_size)
|
||||||
Loading…
Reference in New Issue