# How to build a amplitude modulated tone?

7 Ansichten (letzte 30 Tage)
Paul Hinze am 18 Dez. 2021
Beantwortet: Hema am 1 Mai 2024
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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Star Strider am 21 Dez. 2021
If the Signal Processing Toolboox is available, the modulate function makes this relatively straightforward.
.

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Ashutosh Singh Baghel am 21 Dez. 2021
Bearbeitet: Ashutosh Singh Baghel am 21 Dez. 2021
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'.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Hema am 1 Mai 2024
sir, can I get a MATLAB simulink based simulation for "SIMULINK BASED DPD FOR QPSK TRANSMITTER" which is using DPD in QPSK transmitter section to avoid distortions caused by power amplifier
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Pulse and Transition Metrics finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by