How to build a amplitude modulated tone?
5 次查看(过去 30 天)
显示 更早的评论
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
2021-12-21
If the Signal Processing Toolboox is available, the modulate function makes this relatively straightforward.
.
回答(2 个)
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)];
0 个评论
Hema
2024-5-1
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 QPSK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!