How to play a note

조회 수: 22 (최근 30일)
tom cohen
tom cohen 2021년 10월 21일
댓글: tom cohen 2021년 10월 24일
Hi, why can't i play this?
fs = 8192;
dt = 1/fs;
L = 1;
L=L*fs;
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));

답변 (1개)

Dave B
Dave B 2021년 10월 21일
편집: Dave B 2021년 10월 21일
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:
sound(double(Note))
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
  댓글 수: 7
Dave B
Dave B 2021년 10월 22일
No problem, I'm not sure what else I can add here, you can grab a chunk of y based on the index, and then filter it and put it back in (?):
fs = 8192;
t = linspace(0,.25,fs*.25);
freq(1) = 261.63;
freq(2) = 659.26;
freq(3) = 440;
notes = nan(1,numel(t));
for i = 1:numel(freq)
notes(i,:) = sin(2*pi*freq(i)*t);
end
silence = zeros(1, round(fs*.1));
master_y = [notes(1,:) silence notes(2,:) silence notes(3,:)];
master_t = linspace(0, numel(master_y)/fs, numel(master_y));
[b,a] = butter(8, [500 800]/(fs/2), 'stop');
segment_start = numel(t) + numel(silence) + 1;
segment_stop = 2*numel(t) + numel(silence) + 1;
master_y(segment_start:segment_stop)=filtfilt(b,a,master_y(segment_start:segment_stop));
plot(master_t,master_y);
tom cohen
tom cohen 2021년 10월 24일
that's great, thank you very much for your help :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by