How to play a note

14 views (last 30 days)
tom cohen
tom cohen on 21 Oct 2021
Commented: tom cohen on 24 Oct 2021
Hi, why can't i play this?
fs = 8192;
dt = 1/fs;
L = 1;
t = (0:1:L-1)*dt-0.5;
NoteFreq1 = 261.63;
NoteFreq2 = 659.26;
NoteFreq3 = 440;
NoteDuration = 0.25;
NoteSpace =0.1;
Note=abs(t)<=((NoteDuration/2).*cos(2*pi*NoteFreq1*t)+((NoteDuration/2)+ NoteSpace).*cos(2*pi*NoteFreq2*t)+((NoteDuration/2)- NoteSpace).*cos(2*pi*NoteFreq3*t));

Answers (1)

Dave B
Dave B on 21 Oct 2021
Edited: Dave B on 21 Oct 2021
The Note you made is a logical: you're asking where abs(t) is less than or equal to (a bunch of stuff)
If you want to play this logical, you can by just casting it to double:
But I'm not sure if that's what you intended...maybe it was more like:
Note=double(abs(t)<=((NoteDuration/2))) .* cos(2*pi*NoteFreq1*t)+((NoteDuration/2)+ NoteSpace).*cos(2*pi*NoteFreq2*t)+((NoteDuration/2)- NoteSpace).*cos(2*pi*NoteFreq3*t);
Some suggestions:
  • Break out the Note = line into a few variables, it will make it easier to keep track of the ()s
  • plot(Note) to make sure it's what you expect
tom cohen
tom cohen on 24 Oct 2021
that's great, thank you very much for your help :)

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by