How can I plot the frequency content of my sample?

62 vues (au cours des 30 derniers jours)
Jules Marrison
Jules Marrison le 10 Jan 2020
Commenté : Meg Noah le 13 Jan 2020
Im trying to find the frequecny content of an audio signal and plot it. So far I have :
clear all %Clears the Workspace
close all %Closes all figue/plot windows opened by MATLAB
clc %Clears the command window
[Sample, Fs] = audioread('Snare_1.wav');
Sample = Sample(:,1);
period = 1/Fs;
t = 0:period:(length(Sample)*period)-period;
figure(1)
plot(t,Sample);
grid
xlabel('Seconds (s)');
ylabel('Amplitude');
xlim([0 0.8])
ylim([-0.1 0.1])
But I just cant figure out how to analyse the frequency content, please help if you can
https://we.tl/t-LlzN3QxitD : This is the snare file
  3 commentaires
Tiago Dias
Tiago Dias le 10 Jan 2020
Hi, could you please attach the Snare_1.wav file?
Jules Marrison
Jules Marrison le 10 Jan 2020
https://we.tl/t-LlzN3QxitD This is the snare file

Connectez-vous pour commenter.

Réponses (1)

Meg Noah
Meg Noah le 11 Jan 2020
Did you find a solution yet? Here's one. I wasn't sure if you wanted the frequencies identified or just plotted.
clear all %Clears the Workspace
close all %Closes all figue/plot windows opened by MATLAB
clc %Clears the command window
[X, Fs] = audioread('Snare_1.wav');
X = X(:,1);
N = numel(X);
T = 1/Fs; % [s] sampling period
t = (0:N-1)*T; % [s] Time vector
deltaF = Fs/N; % [1/min]) frequency intervalue of discrete signal
figure(1)
subplot(2,1,1);
plot(t,X);
grid
xlabel('Seconds (s)');
ylabel('Amplitude');
xlim([0 0.8])
ylim([-0.1 0.1])
title('Amplitude of Wave');
% compute the fast fourier transform
Y = fft(X);
% manually shifting the FFT
Y = abs(Y/N);
Amp = [Y(ceil(end/2)+1:end)' Y(1) Y(2:ceil(end/2))']';
if (mod(N,2) == 0)
sampleIndex = -N/2:1:N/2-1; %raw index for FFT plot
else
sampleIndex = -(N-1)/2:1:(N-1)/2; %raw index for FFT plot
end
AmpSquared = Amp.^2;
subplot(2,1,2);
plot(deltaF*sampleIndex, AmpSquared);
hold on;
idx = find(AmpSquared > 15);
idx(sampleIndex(idx) < 0) = [];
plot(deltaF*sampleIndex(idx), AmpSquared(idx), '+');
xlabel('Frequency [Hz]');
ylabel('|FFT(Wave)|^2');
title('Power of FFT of Wave (Audible Range = 20-20\times10^4 Hz)');
xlim([20 2000]);
Snare.png
  4 commentaires
Jules Marrison
Jules Marrison le 13 Jan 2020
So how can i impliment this onto my Y axis?
Sorry to pester im new to matlab
Meg Noah
Meg Noah le 13 Jan 2020
It's a little complicated, because dB should have some sort of reference value to make them meaningful. I need to think about it a little more about whether or not .wav files have an implied reference that equates dB to energy in Watts or volume. There are some more complicated bandpass (frequency range) considerations for audio, because hearing ranges are limited.
Technically, this is 'dB' but audio community may have additional caveats. I'll think about it some more.
clear all %Clears the Workspace
close all %Closes all figue/plot windows opened by MATLAB
clc %Clears the command window
[X, Fs] = audioread('Snare_1.wav');
X = X(:,1);
N = numel(X);
T = 1/Fs; % [s] sampling period
t = (0:N-1)*T; % [s] Time vector
deltaF = Fs/N; % [1/min]) frequency intervalue of discrete signal
figure(1)
subplot(2,1,1);
plot(t,X);
grid
xlabel('Seconds (s)');
ylabel('Amplitude');
xlim([0 0.8])
ylim([-0.1 0.1])
title('Amplitude of Wave');
% compute the fast fourier transform
Y = fft(X);
% manually shifting the FFT
Y = abs(Y/N);
Amp = [Y(ceil(end/2)+1:end)' Y(1) Y(2:ceil(end/2))']';
if (mod(N,2) == 0)
sampleIndex = -N/2:1:N/2-1; %raw index for FFT plot
else
sampleIndex = -(N-1)/2:1:(N-1)/2; %raw index for FFT plot
end
subplot(2,1,2);
plot(deltaF*sampleIndex, 20*log10(Amp));
hold on;
idx = find(Amp.^2 > 15);
idx(sampleIndex(idx) < 0) = [];
plot(deltaF*sampleIndex(idx), 20*log10(Amp(idx)), '+');
xlabel('Frequency [Hz]');
ylabel('dB');
title('Power of FFT of Wave (Audible Range = 20-20\times10^4 Hz)');
xlim([0 2e4]);
It's basically some sort of noise, not pure tone content for this drum.
dB.png

Connectez-vous pour commenter.

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by