How do i plot the phase of fft values in a matrix?

6 visualizzazioni (ultimi 30 giorni)
So in this code we're basically taking an input audio sample, cropping it, taking the fft of the input audio matrix, and then using that to separate human voice from the background instrumental.
So basically, we look at the fft of the input audio, and then remove the frequencies that dont contribute much to the signal. We assign these values two two matrices, one for the human voice, and one for the background voice. Then we take ifft and get the filtered signals back.
My question is, how exactly do I plot the phase of the human voice and background voice. I plotted magnitude plots for both ffts, but i dont know how to plot the phase of the ffts/of the signals. I would greatly appreciate any help.
clc;
clear all;
close all;
% Reads data from the file, and returns sampled data, a, and a sample rate for that data, fs.
[a,fs]=audioread('C:\Users\benpa\AudioSample\starset.wav');
% fs=48000;
% setting length of array in order of 2^n (n=20)
b=a(1:1048576,:);
Length_audio=length(b); %Calculating length of b
df=fs/Length_audio; %Frequency Resolution
%df = 48000/1048576 = 0.0458
frequency_audio=-fs/2:df:fs/2-df; %Nyquist Frequency
figure %creates a new figure window
% time domain plot of input signal
plot(b)
title(' Input Audio');
xlabel('Time(s)');
ylabel('Amplitude');
%sound(a,fs);
%%
% Taking fft of b and then shifting zero frequency component to the centre
%of the array using fftshift
FFT_audio_in=fftshift(fft(b))/length(fft(b));
f4=FFT_audio_in;
figure
% frequency domain plot of input signal
plot(abs(FFT_audio_in));
title('FFT of Input Audio');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
%%
% Initializing zero matrix of same size as that of original matrix
%f2 matrix is for background music and f3 contains human voice
f3=zeros(1048576,2);
f2=zeros(1048576,2);
%seleting particular band that dominates our signal i.e. has contributed
%maximum to our signal( decided by looking at amplitude in frequency domain)
%and making new matrix
for i=1:1048576
for j=1:2
if (i<=400000 || i>=648576)
f2(i,j)=FFT_audio_in(i,j);
end
if ((i>=472288 && i<=514288))||(i>=534288 && i<=576288)
f3(i,j)=FFT_audio_in(i,j);
end
end
end
%f2 is for background music and f3 (which has the dominating part)is for voice of singer
%for converting fft of human voice to audio file
f1=(f3);
l1=length(f1);
sign=(ifft(ifftshift((f1)*length(b))));
de=fs/l1;
fa=-fs/2:de:fs/2-de;
figure
plot(fa,abs(f1))
title('FFT of Human Voice Audio');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
% we want real part of our signal, that's why we are extracting that using
% Re(z)=(z+z')/2
outh=(sign+conj(sign))*0.5;
audiowrite('human.wav',outh,fs); % Writes a matrix of audio data, outh, with sample rate fs to a file called human.wav
%sound(outh,fs); %gives output audio signal or human voice
figure
%plot of output
plot(outh);
title('Human voice Audio');
xlabel('time');
ylabel('Amplitude');
%%
f1=(f2);
l1=length(f1);
sign=(ifft(ifftshift((f1)*length(b))));
de=fs/l1;
fa=-fs/2:de:fs/2-de;
figure
plot(fa,abs(f1))
title('FFT of Background Audio ');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
outb=(sign+conj(sign))*0.5;
audiowrite('back.wav',outb,fs); % Writes a matrix of audio data, outb, with sample rate fs to a file called back.wav
%sound(outb,fs); %gives output audio signal of background audio
figure
%plot of output background audio
plot(outb);
title('Background Audio');
xlabel('Time');
ylabel('Amplitude');
figure
%plot of output background audio
plot(outb);
title('Background Audio');
xlabel('Time');
ylabel('Amplitude');

Risposte (1)

Star Strider
Star Strider il 8 Mag 2022
Use the angle function to calculate the phase from the complex fft result. The unwrap function may also be helpful, depending on the desired result.
The phase spectrum would be plotted with respect to the same independent variable vector (likely ‘frequency’) as the amplitude spectrum.

Categorie

Scopri di più su Measurements and Spatial Audio in Help Center e File Exchange

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by