Multiply sound by pulse
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hannah Krisinger
el 29 de Mzo. de 2020
Comentada: Image Analyst
el 30 de Mzo. de 2020
How do I make a pulse and make the time of the pulse match the audio file time? For the pulse I would like the period to be 2 seconds, and amp of 1, and a duty cycle of 50%. I would then like to multiply the pulse by the audio file.
1 comentario
Image Analyst
el 30 de Mzo. de 2020
You shouldn't have completely replaced your original question with a new question. Now our answers below don't make much sense anymore. Anyway, you can see in my answer where I compute the audioTime. If your pulse (both 1 and 0 parts) was the length of that file, then you can't have a period of 2 seconds (unless the audio time was 2 seconds also).
Respuesta aceptada
Image Analyst
el 29 de Mzo. de 2020
Editada: Image Analyst
el 29 de Mzo. de 2020
Is your signal stereo instead of monochannel? You need to take that into account.
See this little demo for mono, and adapt as needed:
% Initialization steps.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
% Read in the sound.
[y, Fs] = audioread('guitartune.wav');
% load('handel.mat'); % Another sound you can load.
% Play the sound.
soundsc(y, Fs);
% Compute the time axis
t = (1 : length(y)) / Fs;
subplot(3, 1, 1);
plot(t, y, 'b-', 'LineWidth', 2);
title('Original Audio Waveform', 'FontSize', fontSize);
xlabel('Seconds', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
xticks(1 : round(t(end)));
grid on;
drawnow;
audioTime = length(y) / Fs; % In seconds.
fprintf('Audio length = %.3f seconds.\n', audioTime);
% Compute how many seconds 2 seconds is.
pulseWidth = Fs; % Whatever it needs to get 1 (half of 2) of whatever units you're using.
onePulse = [ones(1, pulseWidth), zeros(1, pulseWidth)];
% Replicate as many times as we need (more actually)
numReps = ceil(audioTime/2);
pulseTrain = repmat(onePulse, [1, numReps]);
% Now crop down to the actual signal length that y is
pulseTrain = pulseTrain(1 : length(y));
% Reshape to be a column vector like y
pulseTrain = pulseTrain(:);
% Plot the pulse train.
subplot(3, 1, 2);
plot(t, pulseTrain, 'b-', 'LineWidth', 2);
title('Pulse Train', 'FontSize', fontSize);
xlabel('Seconds', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
grid on;
xticks(1 : round(t(end)));
% Multiple the pulse train by the audio signal and plot.
yPulsed = y .* pulseTrain;
% Plot the pulse train.
subplot(3, 1, 3);
plot(t, yPulsed, 'b-', 'LineWidth', 2);
title('Pulsed Waveform', 'FontSize', fontSize);
xlabel('Seconds', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
grid on;
xticks(1 : round(t(end)));
pause(audioTime);
% Play the sound.
soundsc(yPulsed, Fs);
fprintf('Done running %s.m ...\n', mfilename);

0 comentarios
Más respuestas (1)
Ameer Hamza
el 29 de Mzo. de 2020
Try this
load handel.mat
sound(y, Fs); % original sound
pause(9)
time_tot = numel(y)/Fs;
mod_signal = gensig('square', 1, time_tot-1/Fs, 1/Fs);
mod_sound = y.*mod_signal;
sound(mod_sound, Fs); % modulated sound
0 comentarios
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!