How to build a amplitude modulated tone?

조회 수: 8 (최근 30일)
Paul Hinze
Paul Hinze 2021년 12월 18일
댓글: Star Strider 2021년 12월 21일
Hello,
I would like to program a Amplitude modulated tone according to the formula:
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
Since I am not an expert into math and signal processing, I only get an array of zeros. This formula will come in the last line before plotting. Can someone help me finding the bug in the code?
Best,
Paul
Here is my Code:
%% simulation parameters
clear
close all
clc
% stimulus sound parameters
Fq_ipsi = 2000; % [Hz] low-frequency stimulation
LvdB_ipsi = 80; % sound level [dBSPL]
LvPa_ipsi = 10^(LvdB_ipsi/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_ipsi = 0; % [rad] initial phase
Fq_contra = 2000; % [Hz] high-frequency stimulation
LvdB_contra = 80; % sound level [dBSPL]
LvPa_contra = 10^(LvdB_contra/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_contra = 0; % [rad] initial phase
% time steps
DTms = 0.01; % [ms] time step -- 100kHz sampling rate
% time lengths
Tall = 50; % [ms] entire duration of simulation
Tinit = 15; % [ms] starting time of stimulus
Tstim = 25; % [ms] duration of entire stimulus
Tramp = 3.9;% [ms] duration of stimulus ramp
Tlast = 10; % [ms] time after stimulus
Nall = round(Tall /DTms);
Ninit = round(Tinit/DTms);
Nstim = round(Tstim/DTms);
Nramp = round(Tramp/DTms);
Nlast = round(Tlast/DTms);
tvms = (0:Nall-1)*DTms-Tinit; % time vector (stimulus starts at time zero)
lmain = logical( [zeros(1,Ninit),ones(1,Nstim),zeros(1,Nlast)] );
% constructing sound stimuli
disp('Making sound stimuli');
% stimulus sound envelope (ramp)
SoundEnv = zeros(1,Nall);
% SoundEnv(Ninit+1 :Ninit+Nramp+1) = (0:Nramp)/Nramp; % upward ramp
SoundEnv(Ninit+1 :Ninit+Nstim+1) = 1; % stimulus
% SoundEnv(Ninit+Nstim-Nramp+1:Ninit+Nstim+1) = (Nramp:-1:0)/Nramp; % downward ramp
% Set-up for Amplitde modulated tone
fm = 128; % modulation frequency [Hz]
n = 1; % exponent
m = 1; % modulation depth
% stimulus sound waveforms
Carri_ipsi = sin( 2 * pi * Fq_ipsi * ((tvms-Tinit)/1000) + phase_ipsi); % carrier sine wave
Carri_contra = sin( 2 * pi * Fq_contra * ((tvms-Tinit)/1000) + phase_contra); % carrier sine wave
Sound_ipsi = sqrt(2) * LvPa_ipsi * SoundEnv .* Carri_ipsi; % apply ramp and scale to Pa
Sound_contra = sqrt(2) * LvPa_contra * SoundEnv .* Carri_contra; % apply ramp and scale to Pa
% Make the Signal Amplitude modulated tone
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
figure()
subplot(2,1,1)
plot(tvms, stim)
subplot(2,1,2)
plot(tvms, Sound_contra)
title('Carrier')
xlabel ('Time / ms')
ylabel('Amplitude')
  댓글 수: 1
Star Strider
Star Strider 2021년 12월 21일
If the Signal Processing Toolboox is available, the modulate function makes this relatively straightforward.
.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ashutosh Singh Baghel
Ashutosh Singh Baghel 2021년 12월 21일
편집: Ashutosh Singh Baghel 2021년 12월 21일
Hi Paul,
I understand you are trying to implement Amplitude modulation. The BODMAS rule states we should calculate the Brackets first, then the Orders, then any Division or Multiplication, and finally any Addition or Subtraction. Here also,
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
Here, the last term "2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)" is equal to -1 . So when +1 is added, this sums up to 0. Thats the reason for getting 'stim' signal as zero overall.
By simply adding a brackets in this line of code as follows, will solve the issue.
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*((((1-cos(2.*pi.*fm))./2).^n-0.5)+1)];
For more reference, go to MATLAB Documentation for 'amplitude modulation'.

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by