How to add the level to a sine tone?

조회 수: 2 (최근 30일)
Paul Hinze
Paul Hinze 2021년 4월 18일
댓글: Paul Hinze 2021년 4월 18일
Hi,
I already built the noise and the sine tone, but how can i add the level (in dB SPL) to the noise and sine tone?
% Set-up parameters
fs = 22050; % This is the sampling frequency of the Titan
stim_dur = 1.; % duration of puretone in seconds
noise_dur = 1.; % duration of noise in seconds
ISI_dur = .020; % ISI duration in seconds
ramp_dur = .010; % ramp duration in seconds
t = 0:1/fs:stim_dur-1/fs; % Time vector
f = 10e2; % Frequency
levels = 60:5:100; % Levels dB SPL
% Create noise
nsamples = floor(noise_dur*fs);
noise_all_Hz = randn(nsamples,1);
noise = bandpass(noise_all_Hz,[950 1050],fs);
noise = noise';
% Create 1000 Hz tone
tone = sin(2*pi*f*t);
% Setup ramp
rampSamps = floor(fs*ramp_dur); % Round toward minimum of sampling frequency and duration of ramp
window = hanning(2*rampSamps)'; % hanning window is cosine^2 this will change depending on the kind of ramp you want
w1 = window(1:ceil((length(window))/2)); % use the first half of hanning function for onramp
w2 = window(ceil((length(window))/2)+1:end); % use second half of hanning function of off ramp
w_on_tone = [w1 ones(1,length(tone)-length(w1))]; % Create rising/starting ramp for tone
w_off_tone = [ones(1,length(tone)-length(w2)) w2]; % Create falling/ending ramp for tone
w_on_noise = [w1 ones(1,length(noise)-length(w1))]; % Create rising/starting ramp for noise
w_off_noise = [ones(1,length(noise)-length(w2)) w2]; % Create falling/ending ramp for noise
% Ramp stimuli
noise_ramped = noise.*w_on_noise.*w_off_noise; % Add both ramps to the noise
tone_ramped = tone.*w_on_tone.*w_off_tone; % Add both ramps to the tone

답변 (1개)

Jonas
Jonas 2021년 4월 18일
the level of a sound is usually the root mean square of the amplitude values. going on from there db SPL is calculated as 20*log10(rmsValue/(20*10^-6)). if you reverse my description you get the factor with which you have to multiply your sound.
  댓글 수: 2
Jonas
Jonas 2021년 4월 18일
note that if you have a simple sine with amplitude A, the rms is just A/sqrt(2)
Paul Hinze
Paul Hinze 2021년 4월 18일
Thank you! I will try that

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

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by