Question

In: Electrical Engineering

What would I add to the following code to detect the pitch of the audio signal?...

What would I add to the following code to detect the pitch of the audio signal? (use cepstral method)

clear all;
close all;
clc;

info = audiodevinfo;

info.input(1)
info.input(2)
pause(3); % delete it if necessary

clc;

fs = 44.1e3;
noBits = 16;
noChannels = 1;

recordObject = audiorecorder(fs,noBits,noChannels);

disp('Start speaking...');
record(recordObject);
pause(3);
stop(recordObject);
disp('End of Recording.');

x = getaudiodata(recordObject); %takin in as aperiodic signal
noSamples = length(x); %length of vector x "max(size(x))
time = [1:noSamples]/fs; %time ticks

%DFT: X[k]= (sigma x[n]*exp(-j*2*pi*k/Nf*n)
noSamples = length(x2)
noFrequencies = noSamples;
for ct =1:noSamples
X = nan(size(x2));
for k = 1:noFrequencies
X(k) = sum(x2.*exp(-j*2*pi*k/noFrequencies*n));
end

figure;
subplot(2,1,1);
kAsFrequencyIndicies = 1:noFrequencies;
plot(kAsFrequencyIndicies,abs(X));
box off;
subplot(2,1,2);
frequencyTicks = kAsFrequencyIndicies/noFrequencies*fs;
plot(frequencyTicks,abs(X));
box off;

Solutions

Expert Solution

This code is in MATLAB, It records a signal using audiorecorder function.I recorded a signal where i repeatedly kept saying "A". This code extracts pitch and formant using Cepstral Analysis. At the end it prints letter "A" in Notepad.

Here is a code and the screenshot of it:

clc
rec = audiorecorder(1000,16,1);
disp('Start speaking.')
recordblocking(rec, 2);
disp('End of Recording.');
y = getaudiodata(rec);
w=hamming(2000);
c=y.*w;
x=fft(c);
e=log(abs(x));
g=ifft(e);
d=g(1:length(g)/2);
l=[ones(1,25) zeros(1,975)];
M=transpose(d);
f=M.*l;
%subplot(4,1,2);
%plot(f);
p=f(1:25);
%subplot(4,1,3);
%plot(p);
s=fft(p,8000);
%subplot(4,1,4);
%plot(abs(s));
z=s(1:4000);
%subplot(4,1,1);
%plot(real(z));
k=1;
for i=2:length(z)-1;
    if(z(i-1)<z(i)) & (z(i+1)<z(i))
        formant_mag(k)=z(i);
        formant(k)=i;
        k=k+1;
    else
        continue;
    end
end
%plot(real(z));
%hold on
%plot(formant,formant_mag,'r*');
%hold off
n=fft(z);
%plot(abs(n));
l2=[zeros(1,25) ones(1,975)];
p=l2.';
M=real(p.*d);
%plot(q)
[t_val,t_loc]=max(M);
pitch_period=t_loc
pitch_frequency=(1/pitch_period)*1000
b=['a'];
fid=fopen('word2.txt','w');
fprintf(fid,'%c',b);
fclose(fid);
type word2.txt
status=dos('notepad word2.txt')

This code doesn't perform Noise filtering.


Related Solutions

Need explanation of MATLAB code which creates echo. (SIGNAL PROCESSING) If the original audio signal is...
Need explanation of MATLAB code which creates echo. (SIGNAL PROCESSING) If the original audio signal is x(t) then the echo is y(t) = x(t) + alpha*x(t-delay) This code below creates this echo however I don't understand how every line of the code works, could someone comment this code so I can understand? [x,Fs] = audioread('Hallelujah.wav'); sound(x,Fs); delay = 0.5; % 0.5s delay alpha = 0.65; % echo strength D = delay*Fs; y = zeros(size(x)); y(1:D) = x(1:D); for i=D+1:length(x) y(i)...
How would I add an automatic please fill out this info to my complete code. Something...
How would I add an automatic please fill out this info to my complete code. Something similar to this code. <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <script>    function phonenumber(inputtxt){           var phoneno = (\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4};       if(inputtxt.value.match(phoneno)){        document.getElementById("yourEntry").innerHTML = document.getElementById("myphone").value;    }    //if(!inputtxt.value.match(phoneno)){        // alert("Does not Work!")        //}    } </script> </head> <body> <form name="form1" action="#"> <input type="text" name="myphone" id="myphone" value="" pattern= "(\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4}" placeholder="(555) 555-1212" required /> <input...
JAVA- How do I edit the following code as minimally as possible to add this method...
JAVA- How do I edit the following code as minimally as possible to add this method for calculating BMI? BMI Method: public static double calculateBMI(int height, int weight) { double BMI = (((double) weight) * 0.453592d) / ((((double) height) * 0.0254) * (((double) height) * 0.0254)); Format f = new DecimalFormat("##.######"); return (f.format(BMI)); } Code: import java.text.DecimalFormat; import java.util.Scanner; public class test2 { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("##.0"); Scanner reader = new Scanner(System.in); System.out.printf("%10s...
I need to add this checkpoint to an existing code that i have in python Checkpoint...
I need to add this checkpoint to an existing code that i have in python Checkpoint 1: Once you have created and tested the Bank Account Class create subclasses to the BankAccount class. There should be two subclasses, CheckingAccount and SavingsAccount. You should add interest_rate to the parent BankAccount class. To the CheckingAccount add variables called per_check_fee default to false and allow_overdraft default to True. To SavingsAccount add the variable transactions_per_month, default it to 5. Create instances of CheckingAccount and...
Change the following code to where it adds an image(leave the image blank, I can add...
Change the following code to where it adds an image(leave the image blank, I can add the image) to the question and to generate the questions and answers in a different order each time you begin the quiz. <!DOCTYPE html> <html lang="en" xmlns=""> <head> <meta charset="utf-8" /> <title>World Cup Quiz</title> </head> <body> <style> #flashcards001 { background-color: white; border: 4px solid black; width: 400px; height: 400px; border-radius: 10px; padding: 10px; margin: 10px; } .buttons001 { background-color: blue; color: white; padding: 5px;...
Change the following code to where it adds an image(leave the image blank, I can add...
Change the following code to where it adds an image(leave the image blank, I can add the image) to the question and to generate the questions and answers in a different order each time you begin the quiz. I have 10 questions but due to chegg not allowing me to post all of my code I shorted it to one question. <!DOCTYPE html> <html lang="en" xmlns=""> <head> <meta charset="utf-8" /> <title>World Cup Quiz</title> </head> <body> <style> #flashcards001 { background-color: white;...
I have recently been intrigued by the following question: What is the difference between the pitch...
I have recently been intrigued by the following question: What is the difference between the pitch of the noise of dripping water between hot and cold water? For example, would cold water create a higher pitched noise while dripping into a pot of water? Or vice versa?
What is meant by a direct signal and an indirect signal. Below is the answer I...
What is meant by a direct signal and an indirect signal. Below is the answer I provided. Can you confirm if this answer should be changed to an indirect signal. And if yes, can you provide an example for an direct signal?   A direct signal is a macro indicator that signals directly what is being measured, An example of a direct signal is if a bank closes $8,300,000 loans in February and $8,500,00 loans in March. In February the average...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j a. How many bits does it take to encode ? b. How many bits needed in register file to store the data?
How would I code the following in assembly language? Use the Keil programming environment to code...
How would I code the following in assembly language? Use the Keil programming environment to code the C8051F330 SiLabs 8051 micro controller. All the documentation is available on efundi. The program shall be done in assembler and you shall use the DJNZ instruction to generate a delay time to flash the LED. The LED shall flash in the following sequence: 1. On for 50mS, 2. Off for 400mS, 3. On for 50mS, 4. Off for 1.5S, 5. Repeat the sequence...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT