i need to write a short matlab script that can do the following. please help Usi
ID: 2294124 • Letter: I
Question
i need to write a short matlab script that can do the following. please help
Using Matlab Create 5 seconds of pleasant sound. Use the "Making Music" slides to guide you. Create a *.wav file (or another common format) so I can listen to the pleasant sound. NOTE: One important thing you need to know (not really understand) is that sampling frequency must but be twice the highest frequency you are trying to create. For example, in my sound "Charge" (that I played for you in class) the highest frequency is the note known as Middle G (on a piano, a.ka Ga) The frequency of this note is 392 Hz. So if I want to create this note using Matlab, I would have to use a sampling rate of at least 784 Hz. I would not be able to create any frequencies higher than 392 Hz.Explanation / Answer
MATLAB code is given below.
clear all;
clc;
Fs = 2000;
t = [0:1/Fs:5/15-1/Fs]; % 5 seconds of piece of music
G = sin(2*pi*392*t); A = sin(2*pi*400*t); F = sin(2*pi*370*t); % notes
B = sin(2*pi*493.9*t); C = sin(2*pi*261.6*t); % notes
line1 = [G,G,A,G,F,A,A,B,A,G,B,B,C,B,A]; % notes piece of music
song = [line1];
sound(song,Fs); % Sound the music
wavwrite(song,Fs,16,'test.wav'); % Write a .wav file named test.wav
Before you understand why you need to sample at atleast twice the frequency, you need to know the concept of NYQUIST FREQUENCY. This is the minimum sampling rate required for a continuous saignal to be reproduced faithfully from it's samples. If the sampling is less than Nyquiest frequency, you will not get the same signal when reconstructed. This exactely is the same reason why you need to sample the G note which is 392 Hz atleast at a rate of 784 samples/sec.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.