{{ message }}

# tiborsimon / smart-sinusoids

The easiest way to generate sine or cosine signals in MATLAB.

## Files

Failed to load latest commit information.
Type
Name
Commit time

# Smart Sinusoids The easiest way to generate a sine or cosine signal in MATLAB. With this library there are almost infinite ways to describe and generate a sinusoid signals.

## Dependecy

To use ssin or scos, you need to download and add to your path Simple Input Parser which is a package that allows you to create functions with a more convenient interface for the users.

## Installation

#### 1. Installing the dependency:

• Run the `install.m` script or the `install` command inside the downloaded `simple-input-parser` folder.
• Done. Now you have Simple Input Parser on your system.

#### 2. Installing Smart Sinusoids

• Run the `install.m` script or the `install` command inside the downloaded `smart-sinusoids` folder.
• Done. You can use Smart Sinusoids (and of course Simple Input Parser too).

## Features

• fast and easy signal generation
• flexible parameter handling
• arbitrary parameter configurations
• optional time vector generation

# Possible parameters Symbol Unit Name
A [] signal amplitude
phi [°] phase in degrees
f [Hz] signal frequency
fs [Hz] sample rate
T [s] signal period
dt [s] sample time
N [] number of periods in the signal
n [] sample count
L [s] signal length
x [st] optional time vector scaling (see details later)

# Possible use cases

With these parameters there are 5 main generation methods for sinusoid signals. Each of them have alternatives that doesn't count as an individual generation method due to the used parameters can be derived from the others if you apply the following formulas: fs = 1/dt, T = 1/f and L=n*dt.

Method index Required parameters CT DT lock Description
1 `n`, `N` No a signal consisting of `n` data points with `N`
periods in it
2 `L`, `N`, `fs` Yes `L` seconds long signal consisting `N` periods
with the frequency `f`
3 `f`, `N`, `fs` Yes a signal sampled at `fs` sampling rate with `N`
periods in it with the frequency `f`
4 `f`, `n`, `fs` Yes Generating a sinusoid signal consisting of `n`
data points sampled at `fs` sampling rate with the frequency `f`
5 `f`, `L`, `fs` Yes a signal sampled at `fs` sampling rate with the
duration of `L` seconds with the frequency `f`

### Case 1

• `n` - number of samples
• `N` - periods in it
``````stem( ssin('n N', 200, 1.5) )
``````

### Case 2

• `L` - signal lenght
• `N` - periods in the signal
• `fs` - with a given sample frequency
``````stem( ssin('L N fs', 0.001, 3, 48e3) )
``````

### Case 3

• `f` - signal frequency
• `N` - periods in the signal
• `fs` - with a given sample frequency
``````stem( ssin('f N fs', 440, 1.3, 48e3) )
``````

### Case 4

• `f` - signal frequency
• `n` - number of samples
• `fs` - with a given sample frequency
``````stem( ssin('f n fs', 440, 200, 48e3) )
``````

### Case 5

• `f` - signal frequency
• `L` - signal lenght
• `fs` - with a given sample frequency
``````stem( ssin('f L fs', 800, 0.001, 48e3) )
``````

In every case every parameter can be substituted with the eqvivalent counterparst. ie. fT, fsdt, L~n,dt ...

The amplitude (A) and phase (phi) are optional with the defualt values A=1 and phi=0.

# Output parameter configurations

There are three output parameter configurations

### No output parameter

In this case Smart Sinusouds will output the signal vector in place. This could be useful during plotting

``````stem( ssin('f N fs', 440, 1.3, 48e3) )

``````

### One output parameter

With this configuration you can save the signal vector into a variable.

``````s = ssin('f N fs', 440, 1.3, 48e3);
stem(s)
``````

### Two output parameter mode

If you would like to use the time vector as well, you can generate it too. The possibble values are the following:

Time vector type x parameter Description
Sample count index Sample indexes from 1 to the number of samples.
Normalized norm Normalized vector spans from 0 to 1.
Time [s] time or s Time duration of the signal in seconds.
Time [ms] militime or ms Time duration of the signal in seconds.
``````[t,s] = ssin('f N fs x', 440, 1.3, 48e3, 'ms');
stem(t,s)
``````

This project is under the MIT license. See the included license file for further details.

The easiest way to generate sine or cosine signals in MATLAB.