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)...
Hi, I need the HTML5 code for the below. About Me **Would like to add a...
Hi, I need the HTML5 code for the below. About Me **Would like to add a image of a plane or something related to travel here. Mia Jo I am taking this class to earn my Computer programmer CL1. Things I Like to Do: Spend time with family Traveling People Watch Places I Want to Go or Have Visited: Dubai- December'18 Enjoyed shopping and the desert safari the most. Cuba- August '18 Enjoyed learning about the culture and history. China-...
I have a working code for a dice game. What is the best way to add...
I have a working code for a dice game. What is the best way to add coding to keep track how many points each player makes? When they tie both players gets no points. When they reach to 100 the game ends or unless the player quit. How would I make it work? <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Dice Game</title> <link rel="stylesheet" type="text/css" href="dice.css"> </head> <body> <div class="row" align="center"> <div class="col-4"> <h3>Your Dice</h3> <img src="diceimages/m1.png" width="100" height="100" alt="roll: 1"...
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...
Can you add more comments explaining what this code does? i commented what I know so...
Can you add more comments explaining what this code does? i commented what I know so far #include<stdio.h> #include<pthread.h> #include<semaphore.h> #include<unistd.h> sem_t mutex,writeblock; int data = 0,rcount = 0; int sleepLength = 2; // used to represent work void *reader(void *arg) { int f; f = ((int)arg); sem_wait(&mutex); // decrement by 1 if rcount = rcount + 1; if(rcount==1) sem_wait(&writeblock); sem_post(&mutex); printf("Data read by the reader%d is %d\n",f,data); //shows current reader and data sleep(sleepLength); // 1 second of "work" is...
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...
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 do I need to implement this code. I need an ADT //--------------------------------------------- // This would...
What do I need to implement this code. I need an ADT //--------------------------------------------- // This would be the Student.h file //--------------------------------------------- #include <iostream> #include <cassert> using namespace std; // each student have a name, an ID (100000000~999999999), and three grades class Student { private: public: Student(); Student(); setName(); setId(); setGrade (); getName(); getId(); getGrade() ; printAll() ; }; //--------------------------------------------- // This would be the Student.cpp file //--------------------------------------------- //====================== YOUR CODE STARTS HERE ====================== Student::Student() //default constructor { } Student::Student(string aName,...
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;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT