hey i am new to matlab , actually i want to fft analysis of honey bee sound wav files . i have done with single file now i want to read and plot all files in folder

2 次查看(过去 30 天)
clc
clear
file1='ch01_day05_2a3';
[y,fs] = audioread('C:\Users\Muhammad Yasir\Downloads\Compressed\project matlab\ch01\ch01_day05_2a3.wav');
L=length(y);
t=(1000*(0:1/fs:(L-1)/fs))';
n = 2^nextpow2(L);
Y=fft(y,n);
P = abs(Y/n);
P = P(1:n/2+1);
P(2:end-1) = 2*P(2:end-1);
power = abs(Y).^2/n; % power of the DFT
power = power(1:n/2+1);
power(2:end-1) = 2*power(2:end-1);
f = fs*(0:(n/2))/n;
f1 = fs*(0:n-1)/n;
figure
subplot(4,1,1)
plot(t,y)
xlabel('Time in mseconds');
ylabel('Audio Level');
title('Plot of bee audio files ');
grid on
grid minor
subplot(4,1,2)
plot(f,P)
title('Single-Sided Magnitude Spectrum of bee audio ')
xlabel('f (Hz)')
ylabel('Magnitude')
grid on
grid minor
subplot(4,1,3)
[pk,j] = findpeaks(P,'SortStr','descend','NPeaks',8);
Peaks(:,j) = f(j);
xx=(f(:,j));
xx=(sort(xx));
[~,loc] = max(P);
plot(f(1:10*loc),P(1:10*loc),f(j),pk,'o')
title(['The maixmum of Magnitude Spectrum occurs at ( ' ,num2str(xx) , ' ) Hz' ])
xlabel('f (Hz)')
ylabel('Magnitude')
grid on
grid minor
subplot(4,1,4)
plot(f,power)
xlabel('Frequency')
ylabel('Power')

采纳的回答

Yasir Muhammad
Yasir Muhammad 2020-12-29
this worked for me
clc
clear
D = 'C:\Users\Muhammad Yasir\Downloads\Compressed\project matlab\ch08';
S = dir(fullfile(D,'*.wav'));
N = numel(S);
y = cell(1,N);
fs = cell(1,N);
for k = 1:N
F = fullfile(D,S(k).name);
[y{k},fs{k}] = audioread(F);
L=length(y{k});
t=(1000*(0:1/fs{k}:(L-1)/fs{k}));
n = 2^nextpow2(L);
Y=fft(y{k},n);
P = abs(Y/n);
P = P(1:n/2+1);
P(2:end-1) = 2*P(2:end-1);
power = abs(Y).^2/n; % power of the DFT
power = power(1:n/2+1);
power(2:end-1) = 2*power(2:end-1);
f = fs{k}*(0:(n/2))/n;
f1 = fs{k}*(0:n-1)/n;
figure
subplot(4,1,1)
plot(t,y{k})
xlabel('Time in mseconds');
ylabel('Audio Level');
title('Plot of bee audio files ');
grid on
grid minor
subplot(4,1,2)
plot(f,P)
title('Single-Sided Magnitude Spectrum of bee audio ')
xlabel('f (Hz)')
ylabel('Magnitude')
grid on
grid minor
subplot(4,1,3)
[pk,j] = findpeaks(P,'SortStr','descend','NPeaks',8);
Peaks(:,j) = f(j);
xx=(f(:,j));
xx=(sort(xx));
[~,loc] = max(P);
plot(f(1:10*loc),P(1:10*loc),f(j),pk,'o')
title(['The maixmum of Magnitude Spectrum occurs at ( ' ,num2str(xx) , ' ) Hz' ])
xlabel('f (Hz)')
ylabel('Magnitude')
name = sprintf('figure_%d.jpg',k);
% Specify some particular, specific folder:
path = fullfile('C:\Users\Muhammad Yasir\Desktop\ch08\', name);
saveas(gcf,path,'png')
end
% Your destination folder

更多回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-12-29
编辑:KALYAN ACHARJYA 2020-12-29

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by