Time and Frequency domain variable delay filter implementation
8 次查看(过去 30 天)
显示 更早的评论
Dear friends, I am working towards developing a variable delay filter (FLANGER) in time and frequency domain and compare the performance and quality. Currently I have the time domain filtering working fine with following code....
clc; clear all; close all;
% BASIC FLANGER y(n) = x(n) + gx[n - M(n)]
[x,Fs] = audioread('guit.mp3');
x = x(:,1);
% CONTROLLING PARAMETERS
delay=0.003; % 3ms max delay in seconds
depth = delay; % Amount of depth
modRate = 2; % rate of flange in Hz
FeedBack = 1; % MIX control. Original signal strength
FlangAmp = 0.5 ; % MIX control. Flanged signal strength
% Change to samples
DELAY = round(delay*Fs); % delay in samples
DEPTH = round(depth*Fs); % mod. depth in samples
MODF = modRate/Fs; % modulation frequency in samples
if DEPTH>DELAY
error('Depth cant be greater than Delay . max depth =< delay, min depth = 0');
return;
end
LEN=length(x); % Samples in input file
DLEN=2+DELAY+DEPTH*2; % Length of the entire delay
Delayline=zeros(DLEN,1); % Vector for delay line
y=zeros(size(x)); % Output vector
for n=1:(LEN)
MOD = (sin(MODF*2*pi*n));
TAP= 1+DELAY+DEPTH*MOD;
F(n)= 1+DELAY+DEPTH*abs(MOD);
%TAP(n)=1+DELAY+DEPTH*MOD(n);
i= floor(TAP);
frac= TAP-i;
Delayline= [x(n);Delayline(1:DLEN-1)];
%Linear Interpolation
y(n)= Delayline(i+1)*frac+Delayline(i)*(1-frac);
end
% construct the output signal with MIX controls.
out = FeedBack*x + FlangAmp*y;
sound(out, Fs);
This produces a nice controllable delay effect as desired. Can i improve the performance of this filter in any way ?? to perform faster and/or better quality.
Also, trying to implement this in frequency domain is giving me horrific results. sounds more like a distortion than flanger. here is the code im trying with ... following above section ..
lfo = (F);
Y = (fft(x));
y2 = abs(Y);
a = lfo' .* Y ;
b = real(ifft(a));
sound(b,Fs);
Could you kindly advise me what exactly am i doing wrong ?? Do i have to use windowing before multiplication here? if yes, how would i control the variable delay.
Thanks :)
0 个评论
回答(1 个)
Sachin Kumar
2017-4-19
nfft = 2^nextpow2(2*LEN);
fax = Fs*(-nfft/2:nfft/2-1)'/nfft;
shft = exp(-1j*delay*2*pi*fax); % w=2*pi*fax,, Frequency function for delay
fsd = fft(x(:,1),nfft); % Take FFT
fsd = fsd.*shft; % Apply delay
dum = ifft(fsd); % Return to time domain
sd(:,1) = real(dum(1:LEN));
sound(sd,Fs);
Use the above code for frequency domain delay.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!