How can I plot the frequency content of my sample?

62 visualizzazioni (ultimi 30 giorni)
Jules Marrison
Jules Marrison il 10 Gen 2020
Commentato: Meg Noah il 13 Gen 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

Risposte (1)

Meg Noah
Meg Noah il 11 Gen 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 Commenti
Jules Marrison
Jules Marrison il 13 Gen 2020
So how can i impliment this onto my Y axis?
Sorry to pester im new to matlab
Meg Noah
Meg Noah il 13 Gen 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

Accedi per commentare.

Categorie

Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by