Generate Alternating Tones Based On Number Of Cycles

조회 수: 3 (최근 30일)
Elijah Hamilton
Elijah Hamilton 2022년 11월 2일
편집: Davide Masiello 2022년 11월 2일
Hi, I need to generate a sine wave that alternates between 5 cycles of 651hz, and 4 cycles of 465hz, 100 times.
My current code works, but the frequency gets rounded to a frequency divisible by 48000.
Can I get any help?
  댓글 수: 3
Elijah Hamilton
Elijah Hamilton 2022년 11월 2일
The code generates a single cycle of a square wave, at a given frequency in hertz.
48000 is the sampling rate in hertz.
465hz would be "rouned" to 461.5384615384615hz.
function f = wave(n)
num = 48000 * (0.5 / n);
f(1:num) = 1;
f = [f, f.*-1];
end
Davide Masiello
Davide Masiello 2022년 11월 2일
So you want to generate a square wave.

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

답변 (1개)

Davide Masiello
Davide Masiello 2022년 11월 2일
편집: Davide Masiello 2022년 11월 2일
I am still quite unsure if this is what you are asking, but I will give it a go.
[t,w] = wave(465);
plot(t,w)
function [t,f] = wave(freq)
t = linspace(0,1/freq,48000);
f(1:48000/2) = 1;
f(48000/2+1:48000) = -1;
end

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by