How to generate onset and offset cosine squared ramps in web audio API? - web-audio-api

web audio API creates following wave forms
-Sine Wave
-Square Wave
-Sawtooth Wave
-Triangle wave
if someone wants to create cosine wave then how can create this wave?
How to generate onset and offset cosine squared ramps

Currently, the only way to make a cosine wave is to use a PeriodicWave with an OscillatorNode.
To create a cosine-squared wave, there are at least 4 ways:
Use a AudioBufferSource with the desired wave
Use a WaveShaperNode to square a cosine wave
Use a GainNode to multiply the cosine wave with itself
Use the property that cos(x)^2 = (1+cos(2*x))/2

Related

AudioKit v5 - Why is the loudness of the DynamicOscillators different depending on which Waveform Table I have set for them?

I am using AudioKit to build a simple music application that plays sound when buttons are pressed. When a button is pressed, I call .openGate() on an Amplitude Envelope that has a Dynamic Oscillator as an input.
However, I notice that when I call .setWaveForm(Table(.sine)) on the DynamicOscillators, the sound coming out of the speakers is very quiet when compared to when I call .setWaveForm(Table(.square)). Using a .sawtooth or .triangle table results in an intermediate loudness.
Ideally, the DynamicOscillators would have the same loudness regardless of which waveform is set.
I have assigned an amplitude of 1.0 to each oscillator.
Any ideas?
I think this is because a squarewave does normally sound louder than a sinewave/triangle when both have the same amplitude. You can observe this behavior on most synths.
The square wave is louder for a given amplitude. This is based on its RMS power. It is literally driving the air more than a sine wave.
The RMS power of a square wave is the amplitude. The RMS power of a sine wave is amplitude/sqrt(2). So to make them match, you should drive the square wave at an amplitude of 0.707 (-3dB)
A sawtooth wave has an RMS of 1/sqrt(3), or 0.577 (-4.8dB). You notice the difference between the square and sine more than between sine and sawtooth because we hear on a log scale (dB). It's a bigger jump from 0 to -3dB than from -3dB to -4.8dB. But if you want all of these to match, you'll need to scale both the sine and square waves down to the sawtooth wave.

What is the phase spectrum and why does it have values for the given graph of a simple sine function

I understand the first 2 graphs, the time domain representation and the frequency domain representation (amplitude spectrum) but I cannot wrap my head around the phase spectrum. Why does it contain a value at f = 100? Is it linked with the bandwidth of the system?
The phase plot is just showing that the phase of the associated sine wave at that frequency is -pi/2. This results from the Fourier transform of a sine wave bing two components, one at positive and one at negative frequency, one with a phase to +90 degrees (pi/2) and the other with a phase of -90 degrees (-pi/2). See The Fourier Transform of the Sine and Cosine Functions for more details

How to extract individual wave component information of a signal?

The signal I am interested in is a vector of wind speed and a vector of time which form a ten minute wind speed profile. How can I extract information on the individual waves which combine to form the full ten minute signal (eg. 10 waves with mean speed 9m/s and frequency 1hz and so on),so i end up with a list of all constituent waves and their frequency, max/min values etc. I have tried cross-correlation comparing a 'test' wave of a few seconds with the ten minute vector but this doesnt seem to work
It seems that you are trying to compute the Discrete Fourier Transform (DFT) of your signal. This can be done by using Matlab's built-in fft function (documentation here).

3-D Plot in MATLAB Containing: Time, Frequency and Power Spectral Density

I am currently working on a project for my Speech Processing course and have just finished making a time waveform plot as well as both wide/narrow band spectrograms for a spoken word in Spanish (aire).
The next part of the project is as follows:
Make a 3-D plot of each word signal, as a function of time, frequency and power spectral density. The analysis time step should be 20ms, and power density should be computed using a 75%-overlapped Hamming window and the FFT. Choose a viewing angle that best highlights the signal features as they change in time and frequency.
I was hoping that someone can offer me some guidance as to how to begin doing this part. I have started by looking here under the Spectrogram and Instantaneous Frequency heading but was unsure of how to add PSD to the script.
Thanks
I am going to give you an example.
I am going to generate a linear chirp signal.
Fs = 1000;
t = 0:1/Fs:2;
y = chirp(t,100,2,300,'linear');
And then, I am going to define number of fft and hamming window.
nfft=128;
win=hamming(nfft);
And then I am going to define length of overlap, 75% of nfft.
nOvl=nfft*0.75;
And then, I am performing STFT by using spectrogram function.
[s,f,t,pxx] = spectrogram(y,win,nOvl,nfft,Fs,'psd');
'y' is time signal, 'win' is defined hamming window, 'nOvl' is number of overlap, 'nfft' is number of fft, 'Fs' is sampling frequency, and 'psd' makes the result,pxx, as power spectral density.
Finally, I am going to plot the 'pxx' by using waterfall graph.
waterfall(f,t,pxx')
xlabel('frequency(Hz)')
ylabel('time(sec)')
zlabel('PSD')
The length of FFT, corresponding to 20ms, depends on sampling frequency of your signal.
EDIT : In plotting waterfall graph, I transposed pxx to change t and f axis.

create a signal in frequency domain having values for frequency(MHZ) and power (dBm)

This is my first question on this site, so I'm sorry if I do something wrong...
What I want is to convert a signal (which I recorded with aSpectrum Analyzer from Texas Instruments) from frequency domain to time domain.
The problem is that the software for the Analyzer can be configured just to show frequency domain, so I can't see signals in time domain. I recorded my signal and I exported it to an Excel file. In that file I have a column with frequencies and another column with powers. How can I create a signal using these 2 vectors in Matlab / Simulink and then convert it in time domain?
The spectrum analyser has gotten you each of the wave frequencies in the original frequency. (To a certain accuracy)
Firstly you will need to convert the dBV power of the signal to V. A formula for this can be found on google. ---logarithmic formulae are tricky formula to type out---
Lets say you have a peak at 5Hz with an amplitude of 3V and one at 7Hz with a amplitude of 2V. (You can have as many waves as you like)
1 rad = 1/(2*pi) Hz
That means: 5Hz = 10*pi rad and 7Hz = 14*pi rad
Now that you you have the frequency in radians you can make the wave. By a summation of cosines.
x(t) = A.cos(wt + [phase shift])
w = wave frequency (rad)
A = wave amplitude (V)
t = time
So your wave is:
x(t) = 3.cos(10*pi*t) + 2.cos(14*pi*t)
x(t) is now your output wave. The units are in V but can be converted back to dBV if you'd like. You can specify how long the wave should be, or how many intervals the wave has by assigning a row vector to t. e.g. (t = [0:0.005:1] will give you five periods of the 5Hz wave and seven of the 7Hz wave.)
Unfortunately there is no way to recover the phase shift data from the original signal with only the spectral data. However, the human ear cannot hear a phase difference in waves so perhaps this is suitable for your application.
If you'd like to learn more about he reconstruction of the wave you should look into how the Fourier Series is constructed.