Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB Code - Question below code function xx = key_2_note(X, keynum, dur) fs=8000; tt=0:(1/fs):dur-(1/fs); n=keynum; freq = 440*(2^((n-49)/12)); xx= real(X*exp(j*2*pi*freq*tt)); end ____________________________________________________________________________________ function song =

MATLAB Code - Question below code

function xx = key_2_note(X, keynum, dur) fs=8000; tt=0:(1/fs):dur-(1/fs); n=keynum; freq = 440*(2^((n-49)/12)); xx= real(X*exp(j*2*pi*freq*tt)); end

____________________________________________________________________________________

function song = playSongtrumpet(theVoices) load bach_fugue.mat fs = 44100; lastpulse=0; curlastpulse=0; for i = 1:length(theVoices) %So this finds the latest pulse and adds the longest duration. lastpulse = curlastpulse; curlastpulse = theVoices(i).startPulses(end) + theVoices(i).durations(end); if curlastpulse > lastpulse lastpulse=curlastpulse; end end

spp = 0.15; %seconds per pulse, theVoices is measured in pulses with 4 pulses per beat song = zeros(1, spp*lastpulse*fs); %Create a vector of zeros with length equal to the total number of samples in the entire song %Then add in the notes for i = 1:length(theVoices) for j = 1:length(theVoices(i).noteNumbers) keynum = theVoices(i).noteNumbers(j); note = key_2_note(1,keynum,spp*theVoices(i).durations(j)); %Create sinusoid of correct length to represent a single note %envelope %Rise of Amplitude(A) is 10%. Drop of Signal (D) is 15%. Delay %(S)of 60%. Drop of Signal (R) is 15%. A=linspace(0,1,0.1*length(note)); D=linspace(1,0.8,0.15*length(note)); S=linspace(0.8,0.8,0.6*length(note)); R=linspace(0.8,0,0.15*length(note)); note = note.*[A D S R] locstart = floor(spp*theVoices(i).startPulses(j)*fs); %Floored to get rid of integer warning locend = floor(locstart+length(note)-1); song(locstart:locend) = song(locstart:locend) + note; end end song = song/max(abs(song)); %no clipping %soundsc() or audiowrite() soundsc(song,fs); audiowrite('bachfugue_2.2.wav',song,fs); %Wav for section 1.6 end

_______________________________________________________________________

Bachfugue is a .mat file below

image text in transcribed

The Question:

I need to implement a trumpet sound to this code. Below are the assignment specifications. I'd just like someone to help me get a grasp of how to implement this. There were 26 different pitches in bachfugue.mat ranging from 37 to 57 (key in key_to_note), but only 9 harmonics in the trumpet chart below? Where do I start? Thanks!

image text in transcribed

1x3 struct with 3 fields Fields startPulsesdurations noteNumbers 1x123 doub.... 1x123 doub.. 1x123 double 1x130 doub... 1x130 doub....1x130 double 1x88 double 1x88 double 1x88 double 2 1x3 struct with 3 fields Fields startPulsesdurations noteNumbers 1x123 doub.... 1x123 doub.. 1x123 double 1x130 doub... 1x130 doub....1x130 double 1x88 double 1x88 double 1x88 double 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago