simultaneous noise and pure tone

4 ビュー (過去 30 日間)
Parisa
Parisa 2020 年 8 月 10 日
コメント済み: Parisa 2020 年 8 月 10 日
Hi, I have a noise stimulus and a tone stimulus. How do I center the tone in the noise?
Any help in this regard is highly appreciated!
%set-up parameters
fs=44100; %CD quality - also conveniently divisible by 30 and 25
stim_dur=.025; %duration of puretone in seconds
noise_dur=.200; %duration of noise in seconds
ramp_dur=.010; %ramp duration in seconds
t=0:1/fs:stim_dur-1/fs;
f=1000;
%create noise
nsamples = floor(noise_dur*fs);
noise_all_Hz=randn(nsamples,1);
% Take fft of the noise
noise_fft = fft(noise_all_Hz);
freqs= [0:size(noise_fft,1)-1]/size(noise_fft,1)*fs;
% Get index for your Frequencies
[~,idx_950] = min(abs(freqs-950));
[~,idx_1050] = min(abs(freqs-1050));
% "zero out" all other bins
noise_fft(1:idx_950) = randn(idx_950,1)*1e-3;
noise_fft(idx_1050:end) = randn(size(noise_fft,1)-idx_1050+1,1)*1e-3;
% Get back time signal
noise = ifft(noise_fft,'symmetric');
noise=noise';
%create 1000 Hz tone
xt=sin(2*pi*f*t);
%setup ramp
rampSamps = floor(fs*ramp_dur);
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_xt = [w1 ones(1,length(xt)-length(w1))];
w_off_xt = [ones(1,length(xt)-length(w2)) w2];
w_on_noise = [w1 ones(1,length(noise)-length(w1))];
w_off_noise = [ones(1,length(noise)-length(w2)) w2];
%ramp stimuli
noise_ramped = noise.*w_on_noise.*w_off_noise;
xt_ramped = xt.*w_on_xt.*w_off_xt;
% scale
rms_xt_ramped=rms(xt_ramped); %check the average intensity of the ramped 500 Hz signal
amp_10dB=10^(-10/20)*rms_xt_ramped; %find the new amplitude that is 10 dB lower
%normalize the xt2_ramped stimulus and then scale to -10 dB
noise_ramped_norm=noise_ramped./rms(noise_ramped);
noise_ramped_10dB=noise_ramped_norm.*amp_10dB;

採用された回答

Shae Morgan
Shae Morgan 2020 年 8 月 10 日
編集済み: Shae Morgan 2020 年 8 月 10 日
How your sounds currently are set up, they are concatenated to be added one onto the other. If you change your concatenation to an addition so they overlap, then that should fix your problem. You'll also need to pad your signal so that it is centered in the noise
pad=zeros(1,(length(noise_ramped_10dB)-length(xt_ramped))/2); %figure out the number of zeros to center the signal
padded_xt=[pad,xt_ramped,pad]; %pad the signal
combined=padded_xt+noise_ramped_10dB; %add the signals together
plot(combined)
  1 件のコメント
Parisa
Parisa 2020 年 8 月 10 日
Thank you so much for your time and help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by