generate a complex sound

8 views (last 30 days)
alex kappen
alex kappen on 8 Mar 2015
Edited: alex kappen on 18 Mar 2015
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 Comment
Christiaan
Christiaan on 11 Mar 2015
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

Sign in to comment.

Answers (1)

Christiaan
Christiaan on 10 Mar 2015
Edited: Christiaan on 10 Mar 2015
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);
This code is obtained from this website and modified for your case.
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

Categories

Find more on Measurements and Spatial Audio in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!