Multiply sound by pulse
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hannah Krisinger
il 29 Mar 2020
Commentato: Image Analyst
il 30 Mar 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 Commento
Image Analyst
il 30 Mar 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).
Risposta accettata
Image Analyst
il 29 Mar 2020
Modificato: Image Analyst
il 29 Mar 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 Commenti
Più risposte (1)
Ameer Hamza
il 29 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!