well folks i am having an issue with plotting a beat frequency fc is the central freq, fdel is the freq deviation, F is the sampling rate, and dur is the duration. here is the code.
if true
% code
end
function x = beatfreq(fc,fdel,F,dur)
t = [0:F:dur]; % time index
x = cos(2*pi*(fc+fdel)*t)+ cos(2*pi*(fc-fdel)*t);
plot(t,x); % plot signal
axis([0 127 -20 20]);
title('Sinusoidal signal x(t)');
xlabel('Time t (sec)');
ylabel('Amplitude');
grid on;
sound(x);
end
the problem i am having is that there is no plot in the figure or no sound. so would one of you more knowledgeable folks steer me in the right direction? also please ignore the if true %code end, that is not part of the code.

 채택된 답변

Star Strider
Star Strider 2018년 2월 7일

0 개 추천

You need to tweak your function just a bit, changing sound to soundsc, and add the sampling frequency to it as the second argument. Note that ‘F’ is the sampling interval in the context of the way you have assigned ‘t’, not the sampling frequency.
Try this:
function x = beatfreq(fc,fdel,F,dur)
t = [0:F:dur]; % time index
x = cos(2*pi*(fc+fdel)*t)+ cos(2*pi*(fc-fdel)*t);
plot(t,x); % plot signal
axis([0 127 -20 20]);
title('Sinusoidal signal x(t)');
xlabel('Time t (sec)');
ylabel('Amplitude');
grid on;
soundsc(x, 1/F);
end
Call it as:
z = beatfreq(3000, 500, 0.001, 15);
to see and hear it work correctly.

댓글 수: 6

justin stephens
justin stephens 2018년 2월 7일
sorry but none of that worked.
Star Strider
Star Strider 2018년 2월 7일
What do you mean by ‘none of that worked’?
Did you use the changes in your function that I made (as I posted it)?
The plot displayed the appropriate waveform and the audio was clear when I ran the function I posted with my call to it ( in R2017b, Windows 10).
justin stephens
justin stephens 2018년 2월 7일
yes i took note of the changes that you had made. there still was no tone and no plot.
Star Strider
Star Strider 2018년 2월 7일
I have no idea what the problem could be.
Save the ‘test_beatfreq.m’ file I attach here in your MATLAB user path and run it by typing test_beatfreq in your Command Window. It worked when I ran it just now.
justin stephens
justin stephens 2018년 2월 7일
its fine, i figured it out. i wasn't using F correctly. i finally have it working. thank you for the help thought!
Star Strider
Star Strider 2018년 2월 7일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

질문:

2018년 2월 7일

댓글:

2018년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by