Creating Sine Waves Within MatLab

18,020

Solution 1

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);

Solution 2

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;
           ^
           ^
Share:
18,020
user1574598
Author by

user1574598

Updated on June 04, 2022

Comments

  • user1574598
    user1574598 almost 2 years

    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?