Block Wise FFT on Audio Signal
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Let us take a audio signal. Divide the audio sequence into non-overlapping block each of 8 samples. Perform fft of each block and concatenate all the fft blocks. Plot the magnitude and phase spectrum.
To verify whether the implementation is correct, divide the fft coefficients into blocks of 8 samples and compute ifft. then compare the ifft with the audio signal. If they are equal then the algorithm is correct.
So, I've tried this code but it's not giving any output
[x,Fs] = audioread('amy.mp3');
x1 = x(:, 1);
a = x1.';
N=8;
for i= 1:27366
temp = a((8*i-7):(8*i));
X=zeros(1, N);
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1)+x(n+1)*exp((-1j*2*pi*k*n)/N);
end
end
Y=zeros(1, N);
for k = 0:N-1
for n = 0:length(x)-1
Y(k+1) = Y(k+1)+(x(n+1)*exp(1i*2*pi*n*k/N));
end
end
end
X;
Y = Y./N;
Z = a - Y
0 commentaires
Réponses (1)
Pramil
le 29 Avr 2024
Modifié(e) : Pramil
le 29 Avr 2024
Hi Sree,
You can use the built-in MATLAB functions “fft” and “ifft” to address the described problem.
Here is a code that works in MATLAB R2023b for your reference:
[x,Fs] = audioread('song.mp3'); % Load the audio file
x1 = x(:, 1); % Use only one channel if stereo
N = 8; % Block size
% Number of blocks
numBlocks = floor(length(x1)/N);
% Initialize an empty array for FFT results
fftBlocks = zeros(1,numBlocks*8);
% Divide the signal into non-overlapping blocks and compute FFT for each block
for i = 1:numBlocks
block = x1((N*(i-1))+1:N*i); % Extract block
fftBlock = fft(block); % Compute FFT of the block
fftBlocks((N*(i-1))+1:N*i) = fftBlock; % Assign the FFT results
end
% Plot the magnitude and phase spectrum of the concatenated FFT blocks
figure;
subplot(2,1,1);
plot(abs(fftBlocks));
title('Magnitude Spectrum');
subplot(2,1,2);
plot(angle(fftBlocks));
title('Phase Spectrum');
% Verification by computing IFFT
ifftBlocks = zeros(1,numBlocks*8);
for i = 1:numBlocks
block = fftBlocks((N*(i-1))+1:N*i); % Extract block
ifftBlock = ifft(block); % Compute IFFT of the block
ifftBlocks((N*(i-1))+1:N*i) = ifftBlock; % Assign the IFFT results
end
% Compare the original audio signal with the IFFT result (after reshaping it to match original signal length)
originalSignal = x1(1:N*numBlocks); % Original signal might need to be truncated to match the length
reconstructedSignal = reshape(ifftBlocks, [], 1);
% Check if they are equal
difference = originalSignal - reconstructedSignal;
disp(['Difference between original and reconstructed signal: ', num2str(sum(abs(difference)))]);
% A very small difference value indicates that the algorithm is correct.
You can know more about “fft” and “ifft” funtions through the following links:
Hope it helps.
0 commentaires
Voir également
Catégories
En savoir plus sur Audio Processing Algorithm Design dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!