I am new to signal processing. I am trying to simulate something similar to IIR/FIR filter with $k$ delays to imitate acoustic echo reflection. The difference equations for FIR and IIR respectively are as follows:
\begin{equation} y(n) = x(n) + \sum_{D=1}^kA(n)x(n-D)+v(n)\;\;\;\;\; (1) \end{equation} \begin{equation} y(n) = x(n) + Ay(n-D(n))+v(n)\;\;\;\;\;\;\;\;\;(2) \end{equation} where $D$ is a delay in samples, the coefficient $A(n)$ describes the changing attenuation related from object reflection and $v(n) ∼ N(0, 10^{−3})$ is the noise.
Equation $(1)$ and $(2)$ can be found on section $VII$, second paragraph of this paper
How to can I implement this? I started by writing the following code in R.
Edit after the answer
install.packages("signal")
t <- seq(0, 1, len = 100)
x <- rnorm(100) + rnorm(length(t),0,0.001)
y <- filter(Arma(b = 0.1, a = 0.1), x)
Unfortunately, the above approach does not allow me to have $a=0$ or $b=0$.
Remark
Maybe following function is generating equation $(1)$:
fir1(39, 0.3)+rnorm(40,0,0.001)
The second equation perhaps is called flange IIR filter, where the delay is not constant, but changing with time. This effect imitates time stretching of the audio signal caused by moving and changing objects in the room.
Response to the answer below
The ARMA equation
$$y(n)=\sum_{0}^Ma(m)x(n−m)+\sum_{k=1}^Kb(k)y(n−k)$$
i.e. AR part is as follows:
$$y(n)=\sum_{0}^Ma(m)x(n−m)$$
and MA part is as follows:
$$\sum_{k=1}^Kb(k)y(n−k)$$
which don't match with equations $(1)$ and $(2)$. In equation $(1)$ the coefficient $A$ depends on $n$. The coefficient update at each iteration.
Probably an answer
Parameters
t <- seq(1, 4000, by = 1)
x<- sin(2*pi*t*2.3)
A<- rnorm(4000)
v<- rnorm(4000,0,0.001)
k <- 20
Equation $(1)$
for(i in 1:4000){
if (i>k){
y[i]<- x[i]+ A[i]*sum(x[(i-(k-1)):i]) + v[i]
}else{
y[i]<- x[i]+ A[i]*sum(x[1:i])
}
}
Equation $(2)$
for(i in 1:4000){
if (i>k){
y[i]<- x[i]+ A[i]*(y[i-i%%k]) + v[i]
}else{
y[i]<- x[i]+ A[i]*(y[1]) + v[i]
}
}
Does the solution make sense? Or do I need to generate $x(n)$ using FIR and IIR filter?
signal
package to avoid reinventing the wheel? $\endgroup$signal
package? $\endgroup$filter()
does exactly what you are asking for. $\endgroup$