How would i plot the phase of the fft of background and human voice in this code?

3 ビュー (過去 30 日間)
Axel Blaze
Axel Blaze 2022 年 5 月 7 日
編集済み: Image Analyst 2022 年 5 月 7 日
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');
Basically the title. How would i plot the phase for background voice and human voice in this code? Any help would be greatly appreciated.

回答 (1 件)

Image Analyst
Image Analyst 2022 年 5 月 7 日
編集済み: Image Analyst 2022 年 5 月 7 日
You can use fft() and plot() assuming you have the background and human in two different signals already. If you don't, look at "the cocktail party problem", "blind source separation", and "independent components analysis".

カテゴリ

Help Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by