Difference between revisions of "Ripple Sounds"

From biophysics
Jump to navigation Jump to search
Line 2: Line 2:
 
%todo
 
%todo
 
===FFT-iFFT method===
 
===FFT-iFFT method===
 +
 +
 
Below is an example of an implementation in matlab. It is based on a broadband signal consisting of pink noise.
 
Below is an example of an implementation in matlab. It is based on a broadband signal consisting of pink noise.
 
The input parameters are  
 
The input parameters are  
Line 13: Line 15:
  
 
<pre>
 
<pre>
     % create array with pink noise
+
     % Generate array with pink noise
    noise = pinknoise(n);
+
pink_noise = pinknoise(n);
 
+
 
    % Create modulation for time domain
+
% Create modulation functions for time domain (velocity modulation)
    sin_modulation_t = sin(2 * pi * ripples_per_sec * t + phi);
+
time_modulation_sin = sin(2 * pi * ripples_per_sec * t + phi);
    cos_modulation_t = cos(2 * pi * ripples_per_sec * t + phi);         
+
time_modulation_cos = cos(2 * pi * ripples_per_sec * t + phi);         
  
    % Create modulation for frequency domain  
+
% Create modulation functions for frequency domain (density modulation)
    sin_modulation_f = sin(2 * pi * ripples_per_octave * octaves);
+
freq_modulation_sin = sin(2 * pi * ripples_per_octave * octaves);
    cos_modulation_f = cos(2 * pi * ripples_per_octave * octaves);
+
freq_modulation_cos = cos(2 * pi * ripples_per_octave * octaves);
 
      
 
      
    % Mirror the modulation frequency components for ifft compatibility
+
% Mirror the frequency modulation components for IFFT compatibility
    sin_modulation_f = [sin_modulation_f, fliplr(sin_modulation_f)];
+
mirrored_freq_mod_sin = [freq_modulation_sin, fliplr(freq_modulation_sin)];
    cos_modulation_f = [cos_modulation_f, fliplr(cos_modulation_f)];
+
mirrored_freq_mod_cos = [freq_modulation_cos, fliplr(freq_modulation_cos)];
 +
 
 +
% Apply time modulation to pink noise
 +
modulated_noise_sin_time = time_modulation_sin .* pink_noise;
 +
modulated_noise_cos_time = time_modulation_cos .* pink_noise;
  
    % Apply time modulation to noise, perform fft
+
% Perform FFT 
    fft_sin_mod_t = fft(sin_modulation_t .* noise);
+
fft_sin_modulated_noise_time = fft(modulated_noise_sin_time);
    fft_cos_mod_t = fft(cos_modulation_t .* noise);
+
fft_cos_modulated_noise_time = fft(modulated_noise_cos_time);
 
    
 
    
    % Apply frequency modulation and perform ifft
+
% Apply frequency modulation  
    sin_modulated = ifft(sin_modulation_f .* fft_sin_mod_t, 'symmetric');
+
fft_modulated_noise_sin_time_freq = mirrored_freq_mod_sin .* fft_sin_modulated_noise_time;
    cos_modulated = ifft(cos_modulation_f .* fft_cos_mod_t, 'symmetric');   
+
fft_modulated_noise_cos_time_freq = mirrored_freq_mod_cos .* fft_cos_modulated_noise_time;   
  
    % Determine the ripple type (ascending vs. Descending)
+
% Perform IFFT to get rippled noise in the time domain
    switch ripple_type
+
sin_rippled_noise = ifft(fft_modulated_noise_sin_time_freq, 'symmetric');
        case ascending
+
cos_rippled_noise = ifft(fft_modulated_noise_cos_time_freq, 'symmetric');
            rippled_noise = sin_modulated + cos_modulated;
 
        case descending
 
            rippled_noise = sin_modulated - cos_modulated;
 
    end
 
  
    % calculate the modulated stimulus         
+
% Determine the ripple type (ascending vs. descending)
     ripple_stimulus = noise + modulation_depth * rippled_noise;
+
switch ripple_type
 +
     case 'ascending'
 +
        combined_rippled_noise = sin_rippled_noise  + cos_rippled_noise;
 +
    case 'descending'
 +
        combined_rippled_noise = sin_rippled_noise  - cos_rippled_noise;
 +
end
  
 +
% Calculate the final modulated stimulus         
 +
rippled_stimulus = pink_noise + modulation_depth * combined_rippled_noise;
 
</pre>
 
</pre>
  

Revision as of 10:09, 16 August 2024

Introduction

%todo

FFT-iFFT method

Below is an example of an implementation in matlab. It is based on a broadband signal consisting of pink noise. The input parameters are

  • t = time domain array
  • octaves = frequency domain array
  • ripples_per_sec = the ripple velocity
  • phi = a phase that can be added to the time modulation
  • ripples_per_octave = the ripple density
  • ripple_type = determines if the ripple is ascending or descending
  • modulation_depth = half the amplitude of the modulation
    % Generate array with pink noise
pink_noise = pinknoise(n);

% Create modulation functions for time domain (velocity modulation)
time_modulation_sin = sin(2 * pi * ripples_per_sec * t + phi);
time_modulation_cos = cos(2 * pi * ripples_per_sec * t + phi);        

% Create modulation functions for frequency domain (density modulation)
freq_modulation_sin = sin(2 * pi * ripples_per_octave * octaves);
freq_modulation_cos = cos(2 * pi * ripples_per_octave * octaves);
    
% Mirror the frequency modulation components for IFFT compatibility
mirrored_freq_mod_sin = [freq_modulation_sin, fliplr(freq_modulation_sin)];
mirrored_freq_mod_cos = [freq_modulation_cos, fliplr(freq_modulation_cos)];

% Apply time modulation to pink noise
modulated_noise_sin_time = time_modulation_sin .* pink_noise;
modulated_noise_cos_time = time_modulation_cos .* pink_noise;

% Perform FFT  
fft_sin_modulated_noise_time = fft(modulated_noise_sin_time);
fft_cos_modulated_noise_time = fft(modulated_noise_cos_time);
  
% Apply frequency modulation 
fft_modulated_noise_sin_time_freq = mirrored_freq_mod_sin .* fft_sin_modulated_noise_time;
fft_modulated_noise_cos_time_freq = mirrored_freq_mod_cos .* fft_cos_modulated_noise_time;   

% Perform IFFT to get rippled noise in the time domain
sin_rippled_noise = ifft(fft_modulated_noise_sin_time_freq, 'symmetric');
cos_rippled_noise = ifft(fft_modulated_noise_cos_time_freq, 'symmetric');

% Determine the ripple type (ascending vs. descending)
switch ripple_type
    case 'ascending'
        combined_rippled_noise = sin_rippled_noise  + cos_rippled_noise;
    case 'descending'
        combined_rippled_noise = sin_rippled_noise  - cos_rippled_noise;
end 

% Calculate the final modulated stimulus          
rippled_stimulus = pink_noise + modulation_depth * combined_rippled_noise;

N.B. when the density is zero 'rippled_noise' by itself has an envelope of a rectified sine wave (which has double the velocity). Only after adding the original noise the envelope is the correct one.

Band filter method

%todo

References