Want to generate a sine wave with linear sweeping in amplitude and output as sound in audio jack

I am trying to make amplitude sweeping of a sine wave and want the output of this wave in the system audio jack.
I have this code working to some extent.
It will make me happy if somebody helps me in this regard.
%%%%%%% Amplitude sweeping %%%%%%%%%%%
clear all;
clc;
Fc = 1000;
Fs = 44100;
dt = 1/Fs;
StopTime = 2;
t = (0:dt:StopTime-dt)';
A = linspace(0, 1, numel(t))';
y = A.*sin(2*pi*Fc*t);
plot(t,y)
grid on
player = audioplayer(y,192000);
play(player);

5 Commenti

please make sure you are playing the audio signal at the same sampling rate you generated it
so this line
player = audioplayer(y,192000);
should be replaced by :
player = audioplayer(y,Fs);
otherwise, your code works
what is the trouble ?
The problem is that there is a mismatch of timing. If I want to generate sound for 5 seconds, I need to change the stop time to 5 seconds, but it actually produces sound for more than 5 seconds.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Audio I/O and Waveform Generation in Centro assistenza e File Exchange

Richiesto:

il 12 Giu 2023

Commentato:

il 14 Giu 2023

Community Treasure Hunt

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

Start Hunting!

Translated by