Problem with my modulated noise

2 ビュー (過去 30 日間)
frankenberry
frankenberry 2018 年 6 月 14 日
回答済み: frankenberry 2020 年 4 月 28 日
SDFAS
  1 件のコメント
Stephen23
Stephen23 2020 年 3 月 26 日
Original question from Google Cache:
"Problem with my modulated noise"
I'm coding some modulated noise but it's coming out weird. I have 8 modulators - one for each of 4 frequencies for each ear (i.e. 4 presented to the left and 4 presented to the right). I used the designfilt option originally but changed to one created by my supervisor that uses fir filter. The output sounds correct but the plot of the image looks way off. This is my code. Please let me know if you can help.
%INPUT VARIABLES
clc;
pth = 'C:\MATLAB\HHL\SAMNoise\';
%carPhase = 0;
Fs=32e3; %sample rate
dur = 1000;%duration in ms
ti = 1/Fs:1/Fs:(dur/1000); %time index
modFreqs = [79 85 91 97]; %modulation frequencies for LE=79 85 91 97 and for RE=83 89 95 101
HPF1 = [421 915 1909 3903]; %Lower bound High Pass Frequency1 for LE 421 915 1909 3903 and RE is 417 911 1905 3899];
HPF2 = [579 1085 2091 4097]; %Upper bound High Pass Frequency2 for LE 579 1085 2091 4097 and RE is 583 1089 2095 4101];
FOrderValue = 300; %filter order value for designfilter
modDepth = 0; %100 percent
modPhase = 0;%modulation phase
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CREATE FILTERS to shape the noise
%for i=1:length(HPF1)
% filts(i) = designfilt('bandpassfir', 'FilterOrder', FOrderValue, 'HalfPowerFrequency1', HPF1(i), 'HalfPowerFrequency2', HPF2(i), 'SampleRate', Fs);
%fvtool(filts(i)); % Use fvtool to visualize a digitalFilter, i
%end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%CREATE THE STIMULUS
% CREATE zero array to store the mod freqs and output noise
modulation = zeros(length(modFreqs),Fs);
NoiseOut = zeros(Fs,length(modFreqs));
%sideAmp = 10.^(modDepth./20);
% % GENERATE the modulator signal
for i=1:length(modFreqs)
modfreq = modFreqs(i);
modSignal = 0.5*(1+cos(2*pi*modfreq*ti+pi));
%CREATE Pink Noise for filter; p = bandpower(x,Fs,freqrange)
pinknoise = dsp.ColoredNoise(1,Fs,1);
rng default;
x = pinknoise();
% ADD filter to shape the pink noise; Use filter in the form dataOut = filter(i,dataIn) to filter a signal with a digitalFilter
NoiseOut(:,i) = cleanfiltfilt(x,Fs,HPF1(i),HPF2(i),1000);
%filtfilt(filts(i),x); % apply the filter
%ADD Modulation to filtered noise
ShpdModNoise(i,:) = modSignal .* NoiseOut(:,i)'; %modulation plus filtered noise
%WRITE out the wav file
scaled_stim(i,:) = ShpdModNoise(i,:).*10^(-16/20);
modFreqsstr = num2str(modFreqs(i));
filenam = [pth 'SAM_Noise' modFreqsstr 'x_24.wav'];
audiowrite(filenam,scaled_stim(i,:)',Fs,'BitsPerSample',24)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%PLOTS
% VISUALIZE the signal
nfft = Fs;
nyq = Fs/2;
fi = 0:nyq;
f = fft(scaled_stim(i,:),nfft);
fAmp = (2/nfft)*abs(f);
h = abs(hilbert(scaled_stim(i,:)));
fh = (2/nfft)*abs(fft(h,nfft));
hold on;
if i > 1
figure;
end
subplot(221)
stairs(fi(2:4501),fAmp(2:4501),'k');
title({'FFT of Spectral Envelope'; 'and Modulation Frequency'});
xlabel('Frequency (Hz)');
ylabel('Amplitude');
%axis([20 4500 0 0.5]);
hold on
stairs(fi(2:4501),fh(2:4501),':r');
legend('Signal','Modulation Frequency');
hold off;
% PLOT the SAM Noise modulation envelope
subplot(222);
plot(scaled_stim(i,1:length(scaled_stim)/100),'k');
title('Modulation Envelope');
xlabel('Time (s)');
% ylabel(' ');
%axis([0 320 -.5 .5]);
%stairs(fi(1:1001),fh(1:1001),'k');
%legend('Modulation Envelope','Carrier Signal');
subplot(212);
plot(scaled_stim(i,1:length(scaled_stim)/10),'k');
title(['Modulated Signal at MF' modFreqsstr]);
xlabel('Time (seconds)');
% ylabel('');
%axis([0 3200 -1 1]);
end
SumShpdModNoise = sum(scaled_stim)
return

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

採用された回答

frankenberry
frankenberry 2020 年 4 月 28 日
Found out that the modulated is supposed to look this way when you combine them. All is well on this.

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 6 月 23 日
When you do this:
MF2sum = zeros(Fs,(i)); %zero array for holding mod freqs
and you haven't defined i in advance (in effect overwriting the imaginary variable), it considers i as 0 + 0*i, which is the imaginary variable.
To fix, you should use a different name, like numPoints or whatever. And you have to define its value before you call zeros().
  2 件のコメント
Image Analyst
Image Analyst 2018 年 6 月 23 日
What looks wrong about it? What does it (the 4 signals added together) look like? What do you think it's supposed to look like?
Image Analyst
Image Analyst 2018 年 6 月 24 日
And what are you passing in to that function for x,Fs,HP,LP,order?

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

Community Treasure Hunt

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

Start Hunting!

Translated by