generate a complex sound
조회 수: 11 (최근 30일)
이전 댓글 표시
I would like to generate a complex sound as follows:
0-6kHz (60db), 6-9kHz (30db),9-20kHz (60db).
Any idea how to do it?
댓글 수: 1
Christiaan
2015년 3월 11일
Dear Alex,
Yes if the amplitude of your signal changes, then the PSF of your signal should change also.
Could you please resend your code by either sending your functions as'attachment' or by using the 'code' button? Please send the code, so that I can exactly reproduce the error you got.
Kind regards, Christiaan
답변 (1개)
Christiaan
2015년 3월 10일
편집: Christiaan
2015년 3월 10일
Dear Alex,
If you would like to create a bandpass with white noise, you could try to use this code:
clc;clear all;close all;
% set general variables
sf = 44100; % sample frequency
nf = sf / 2; % nyquist frequency
d = 2.0; % duration (time)
n = sf * d; % number of samples
nh = n / 2; % half number of samples
% =========================================================================
% set variables for filter
lf = 1; % lowest frequency
hf = 6000; % highest frequency
lp = lf * d; % ls point in frequency domain
hp = hf * d; % hf point in frequency domain
% design filter
clc;
a = ['BANDPASS'];
filter = zeros(1, n); % initializaiton by 0
filter(1, lp : hp) = 1; % filter design in real number
filter(1, n - hp : n - lp) = 1; % filter design in imaginary number
% =========================================================================
% make noise
rand('state',sum(100 * clock)); % initialize random seed
noise = randn(1, n); % Gausian noise
noise = noise / max(abs(noise)); % -1 to 1 normalization
% do filter
s = fft(noise); % FFT
s = s .* filter; % filtering
s = ifft(s); % inverse FFT
s = real(s);
% =========================================================================
% play noise
disp('WHITE noise');
sound(noise, sf); % playing sound
pause(d + 0.5); % waiting for sound end
% play filtered noise
clc;
disp([a, ' noise']);
sound(s, sf); % playing sound
pause(d + 0.5); % waiting for sound end
% =========================================================================
% plot sound
x = linspace(0, d, n);
subplot(2,2,1); plot(x, noise); xlabel('time (s)'); title('sound: noise');grid on;
subplot(2,2,2); plot(x, s); xlabel('time (s)'); title('sound: filtered noise');grid on;
% plot Fourier spectrum
x = linspace(0, nf, nh);
t = fft(noise);
t = t .* conj(t);
subplot(2,2,3); semilogy(x, t(1,1:nh) ./ max(t)); xlabel('frequency (Hz)'); title('spectrum: noise'); grid on;
t = fft(s);
t = t .* conj(t);
subplot(2,2,4); semilogy(x, t(1,1:nh) ./ max(t)); xlabel('frequency (Hz)'); title('spectrum: filtered noise'); grid on;
figure(1);
If you want to generate a sound at a lower amplitude, you can just multiply the output by a factor. (Lb = 10Log10(I/I0)
Good Luck! Christiaan
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!