Low Pass Filtering - Generate a Slowly Changing Signal in Matlab

  • MATLAB
  • Thread starter sarahpaninsky
  • Start date
In summary: Filtered Gaussian Noise');The code produces the following output: In summary, the code produces a filtered gaussian noise signal. The alpha function is a low-pass filter, and the noise is sampled at 8+7*randn(1,5e4). The waveforms are sampled at 1000 Hz, and the cutoff frequency is around 35 Hz.
  • #1
sarahpaninsky
5
0
Hi,
I want to generate a slowly changing signal (1 second duruation).
For this, I must filter white noise with a filter which is characterized by an alpha function as below

alpha(t)= t*exp(-t/tau) ( I think function is low-pass filter response)

where tau=3 ms. I couldn't achive this in matlab. Can anyone help me for this?
Regards
 
Physics news on Phys.org
  • #2
Can you show us your work? We can help you better if we see your approach and your Matlab code.

By the way, is your alpha a step response (probably) or an impulse response?
 
  • #3
marcusl said:
Can you show us your work? We can help you better if we see your approach and your Matlab code.

By the way, is your alpha a step response (probably) or an impulse response?

clear
figure
tau=3;
noise=8+7*randn(1,1e5);
t=[0:0.01:1e3];
y=conv(noise,t.*exp(-t./tau));
subplot(3,1,1)
title('Gaussian Noise')
plot(noise)
subplot(3,1,2)
plot(y)
title('Filtered Noise')

My code is like above.
As I said before the filtered signal must be slowly changing, is like a stimulus not actually like noise to a biological neuron. Please modify my code
 
  • #4
Be careful of your time units. You specified tau=3, implying that your waveforms are sampled at 1000 Hz. Then each point in your sequence is separated by 1 ms. Your impulse response dies to essentially zero after 30 ms, so there's no need to include 1e5 points!

Below I relabeled your t as n to make the point that this is the index of a sampled data sequence, and reduced the length of the impulse response h to 30 points. I also reduced the input sequence noise to 10,000 points so it runs faster, but this is not important.

clear
tau=3;
noise=randn(1,1e4);
n=[0:30];
h = n.*exp(-n/tau);
y=conv(noise,h);
figure
subplot(3,1,1)
title('Gaussian Noise')
plot(noise)
subplot(3,1,2)
plot(y)
title('Filtered Noise')

This does low-pass filter your noise. You can display the frequency response of your filter and output with the following commands:

Fs = 1000;
Hs=spectrum.periodogram
figure
psd(Hs,h,'Fs',Fs)
title('Filter Response')
figure
psd(Hs,y,'Fs',Fs)
title('Output Spectrum')

Fs above is the sampling frequency, 1000 Hz in this case. Notice that your cutoff frequency (-3 dB) is about 35 Hz. You probably studied the relation between time constant and cutoff frequency fc; what is it? See if you can adjust tau to get fc=1 Hz. You'll have to readjust the sampling frequency to match your new tau...
 
  • #5
marcusl said:
Be careful of your time units. You specified tau=3, implying that your waveforms are sampled at 1000 Hz. Then each point in your sequence is separated by 1 ms. Your impulse response dies to essentially zero after 30 ms, so there's no need to include 1e5 points!

Below I relabeled your t as n to make the point that this is the index of a sampled data sequence, and reduced the length of the impulse response h to 30 points. I also reduced the input sequence noise to 10,000 points so it runs faster, but this is not important.

clear
tau=3;
noise=randn(1,1e4);
n=[0:30];
h = n.*exp(-n/tau);
y=conv(noise,h);
figure
subplot(3,1,1)
title('Gaussian Noise')
plot(noise)
subplot(3,1,2)
plot(y)
title('Filtered Noise')

This does low-pass filter your noise. You can display the frequency response of your filter and output with the following commands:

Fs = 1000;
Hs=spectrum.periodogram
figure
psd(Hs,h,'Fs',Fs)
title('Filter Response')
figure
psd(Hs,y,'Fs',Fs)
title('Output Spectrum')

Fs above is the sampling frequency, 1000 Hz in this case. Notice that your cutoff frequency (-3 dB) is about 35 Hz. You probably studied the relation between time constant and cutoff frequency fc; what is it? See if you can adjust tau to get fc=1 Hz. You'll have to readjust the sampling frequency to match your new tau...


Thanks for your interest Marcusl,
But the results are not sufficent.
I want to show you my work, I want to reproduce the low-pass gaussian white noise stimuli as in the image I attached. if you look at it, you may understand my problem with the code. What could I do ? Filtering is Okey but the the code is fails for amplitude and fluctuating?
 

Attachments

  • fig1.JPG
    fig1.JPG
    48.6 KB · Views: 411
  • #6
Sorry, I thought this was a homework assignment. I'll take a close look at this tonight.
What are the spikes they refer to? Are they individual channel responses? What is the significance of jitter? (I work in radar, not membranes...)

Would you post the paper, or link to it?

thx
 
  • #7
my e-mail is "opamp67@hotmail.com", if you send a blank mail, I will send you immediately. Because I cannot attach the paper as the file size limit of the forum.

This is an scientifistic paper on Neuron modelling in biomedical disciplinary. in the paper Figure1 is important for me, especially top two figures which are related to low-pass gaussian noise. My final code is below to produce the signal Fgi1B (top trace)


clear
figure
tau=3;
noise=8+7*randn(1,5e4);
t=[0:0.01:499.99];
h=t.*exp(-t/tau);
y1=(fft(noise));
y2=(fft(h));
y3=(ifft(y1.*y2));
plot(t,y3);
axis([0 500 -2 11])
 
  • #8
I can take a few moments at lunch to make the following comments:
1) You've used tau = 3 sec in your code instead of 3 msec. This will produce a very low frequency output (filter cutoff of 0.05 Hz, according to calc below).

2) You can predict the cutoff (-3dB or half power) frequency of the analog alpha filter as follows. You've specified an impulse response
[tex]\alpha(t)=t\exp{(-t/\tau)}[/tex] which has Laplace transform
[tex]F(s)=\frac{1}{(s+1/\tau)^2}[/tex].
Evaluating [tex]s=i\omega+\sigma[/tex] on the frequency (imaginary) axis
gives the frequency response as
[tex]|F(\omega)|=\frac{1}{|\omega+1/\tau|^2}[/tex].
This is a two pole lowpass filter with cutoff frequency
[tex]f_c=\frac{1}{2\pi\tau}[/tex].
The point is, [tex]\tau=3 ms[/tex] gives a filter rolloff of [tex]f_c=53 Hz[/tex].This is roughly consistent with the waveform in Fig. 1B, and is not consistent with your statement that the waveform should change on the order of seconds.

3) You can see from the expression for F that the filter gain is not normalized to one at zero frequency. Dividing by tau^2 gives proper DC normalization
[tex]\alpha(t)=\frac{t}{\tau^2}\exp{(-t/\tau)}[/tex].

4) In general, sampling the impulse response of an analog filter the way you've done it here is not the optimal way to implement a digital filter. One problem is that analog and digital cutoff frequencies don't match. If you look at the power spectral density of h using the psd commands I gave above, you'll see that the -3dB frequency response of the digital filter using tau=3 ms is around 35Hz instead of the 53 Hz calculated for the analog filter. A sampled impulse response implementation also aliases, so F(w) doesn't roll off towards zero as expected but flattens out. Finally, the DC normalization is thrown off. I assume that is why Fig. 1 shows a mean of about 4, even though the input had a mean of 8 that should be unchanged by the lowpass.

I'm not sure whether these considerations are important to your paper and work, but at least you have an appreciation of what this system is doing from the standpoint of digital signal processing.
 
Last edited:
  • #9
Sorry, there's a typo in the frequency response--there should be an i in front of omega:

[tex]|F(\omega)|=\frac{1}{|i\omega+1/\tau|^2}[/tex]

Of course this simplifies to
[tex]|F(\omega)|=\frac{1}{\omega^2+1/\tau^2}[/tex]
 
  • #10
Ok, the "scientifistic" paper you sent contains no information on the signal processing used within, beyond that mentioned in the Figure attachment above. The fact that the signal mean values in Fig. 1 A,B differ from input to output is strange. We'll take the "filter method" in Fig. 1 at face value, however, lacking any other information. Changing the OP's code as follows at least approximates their results:

clear
tau=3e-3;
noise=8+7*randn(1,1e4);
t=[0:0.001:0.03];
h = t .* exp(-t./tau) ;
y=conv(noise,h/sum(h));
figure
subplot(3,1,1)
plot(noise)
title('Gaussian Noise')
axis([500 1000 0 15])
subplot(3,1,2)
plot(y)
title('Filtered Noise')
axis([500 1000 0 15])
figure
plot(h)
title('Filter Impulse Response')

One-half second of signal is plotted, as in the paper. The filter is normalized ad hoc by dividing by the sum of the impulse response.
 
  • #11
marcusl said:
Ok, the "scientifistic" paper you sent contains no information on the signal processing used within, beyond that mentioned in the Figure attachment above. The fact that the signal mean values in Fig. 1 A,B differ from input to output is strange. We'll take the "filter method" in Fig. 1 at face value, however, lacking any other information. Changing the OP's code as follows at least approximates their results:

clear
tau=3e-3;
noise=8+7*randn(1,1e4);
t=[0:0.001:0.03];
h = t .* exp(-t./tau) ;
y=conv(noise,h/sum(h));
figure
subplot(3,1,1)
plot(noise)
title('Gaussian Noise')
axis([500 1000 0 15])
subplot(3,1,2)
plot(y)
title('Filtered Noise')
axis([500 1000 0 15])
figure
plot(h)
title('Filter Impulse Response')

One-half second of signal is plotted, as in the paper. The filter is normalized ad hoc by dividing by the sum of the impulse response.

That is GREAT Marcusl. I am glad to you. Everything is OK now. Thanks your kind interest.
 

What is low pass filtering?

Low pass filtering is a signal processing technique used to remove high frequency components from a signal, while retaining the low frequency components. This is often used to generate a slowly changing signal from a noisy or rapidly changing input.

How does low pass filtering work?

Low pass filtering works by applying a filter to the input signal that allows only low frequency components to pass through. This is typically achieved by using a convolution with a windowed sinc function or a Butterworth filter.

What is the purpose of generating a slowly changing signal in Matlab?

The purpose of generating a slowly changing signal in Matlab is to reduce noise and make the signal easier to analyze. This can be helpful in various applications, such as in signal processing, audio and image processing, and data analysis.

What is the difference between a low pass filter and a high pass filter?

A low pass filter allows low frequency components to pass through, while attenuating high frequency components. A high pass filter, on the other hand, allows high frequency components to pass through, while attenuating low frequency components.

Can low pass filtering be used for all types of signals?

Low pass filtering can be used for a wide range of signals, including audio, video, and data signals. However, the type of filter and parameters used may vary depending on the specific characteristics of the signal being filtered.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
738
  • Engineering and Comp Sci Homework Help
Replies
16
Views
948
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
1K
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top