Generate Alternating Tones Based On Number Of Cycles
Show older comments
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 Comments
Davide Masiello
on 2 Nov 2022
"My current code works, but the frequency gets rounded to a frequency divisible by 48000."
Not sure what you mean here.
Could you please share your code and clarify the above statement?
Elijah Hamilton
on 2 Nov 2022
Davide Masiello
on 2 Nov 2022
So you want to generate a square wave.
Answers (1)
Davide Masiello
on 2 Nov 2022
Edited: Davide Masiello
on 2 Nov 2022
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
Categories
Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!