How can I plot the frequency content of my sample?

조회 수: 62 (최근 30일)
Jules Marrison
Jules Marrison 2020년 1월 10일
댓글: Meg Noah 2020년 1월 13일
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
Tiago Dias
Tiago Dias 2020년 1월 10일
Hi, could you please attach the Snare_1.wav file?
Jules Marrison
Jules Marrison 2020년 1월 10일
https://we.tl/t-LlzN3QxitD This is the snare file

댓글을 달려면 로그인하십시오.

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by