2
votes

I'm trying to create a sine wave audio signal within MatLab based on this function:

Sinusoidal Functions

So far I have created a vector x that starts at 0, increments in 0.1 to 10

Followed by this:

y = 3*sin(x(2*pi/4))+2;

I have multiplied x by 2*pi/4 in order to resize the period to a quarter of its size, but I have errors regarding indexes being positive.

Also, is it at all possible to actually create a signal at a specific Hz. For example if I wanted a sine wave at 800Hz?

2
Please add your code to the question. - Daniel
Thanks, my next step is to investigate the fft after I master the basics first. - user1574598

2 Answers

4
votes

This code create a signal at a specific Hz and play it.

%duration [s]
T=1;
%sample rate [Hz] Supported by SoundCard (16000,48000,96000,192000)
Fs = 48000;
%samples
N = T*Fs;
%samples vector
t = 0 : 1/Fs : T;
%Frequency [Hz]
Fn = 800;
%Signal
y = sin(Fn*2*pi*t);
plot(t,y);
%Play sound
sound(y,Fs);
3
votes

You are not multiplying correctly. Note the subtle difference

y = 3*sin(x(2*pi/4))+2;

and what you appear to want (note the missing multiplication)

y = 3*sin(x*(2*pi/4))+2;
           ^
           ^