cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

dhgac_296796
New Contributor II

Hello,

   

    I want to access output data of filter in order to visualize the data by plotting. I have used example project ADC_Filter_DMA_Polled. Attached is the old project which I created as a case. At the input I have got a biomedical signal, which goes through filtering. I want to observe filtered signal in digital domain by plotting it. If I convert it in analog domain and then observe then I am not getting expected result. May be that it adds nonlinearities of DAC. What can be the solution for this?  Can I put output of DMA to SRAM and access the data.. and how? Any guidelines??

   

Thanks in Advance !!

0 Likes
1 Solution
JoMe_264151
Expert II

Your timings do not match:

   

WaveDAC delivers a 1kHz sine, SAR converts controlled by PWM at ~1kHz, but should be quite more (Nyquist). Your Filter expects 0.5kHz.

   

I would suggest you to use a frequency of at least 10kHz, change PWM and filter accordingly.

   

You can easily use a second DMA that transfers to a ram-area, maximum size are 4095 bytes with one burst.

   

 

   

Bob

View solution in original post

0 Likes
24 Replies
JoMe_264151
Expert II

Your timings do not match:

   

WaveDAC delivers a 1kHz sine, SAR converts controlled by PWM at ~1kHz, but should be quite more (Nyquist). Your Filter expects 0.5kHz.

   

I would suggest you to use a frequency of at least 10kHz, change PWM and filter accordingly.

   

You can easily use a second DMA that transfers to a ram-area, maximum size are 4095 bytes with one burst.

   

 

   

Bob

View solution in original post

0 Likes
dhgac_296796
New Contributor II

Thanks Bob for your time. I have configured 50 Hz notch filter. If I change the filter sample rate, it does not give appropriate response, the notch disappears, rather attenuation decreases. Hence I had seleted such settings. Morover in order to test if filter passes all other frequencies than 50 Hz, I had set 1 KHz at waveform generator. Anyway I will try DMA with SRAM as well. 

0 Likes
JoMe_264151
Expert II

I was wrong with the filter settings. Try those on the picture.

   

 

   

Bob

0 Likes
dhgac_296796
New Contributor II

Thanks Bob. It has solved my notch filter problem. I am getting nice frequency response. However when I add one more filter stage, Band pass filter with Biquad, it is not giving appropriate response. If I add FIR stage for bandpass, I am getting response shown in figure attached. Should I add filter gain ?? How does it affect the performance of filter?

0 Likes
JoMe_264151
Expert II

"Should I add filter gain ??" As I understand: just the other way, you have to reduce the gain, so that there will be no internal overflows possible. This of course reduces the peak-to-peak output of the filter. Check for your prerequisites of the project if you really need a filter that steep. Maybe a filter with a 20db attenuation would be quite sufficient and 140db is quite a bit too much.

   

 

   

Bob

0 Likes
dhgac_296796
New Contributor II

In my case, signal is in the range of 0.5 Hz to 150 Hz. Hence I want a notch filter to remove power line noise and bandpass filter to pass frequencies of interest. If I configure filter as Biquad, it is adding high ripples and the filtered signal I get is distorted. The problem is if I increase sampling frequency, frequency response is getting worst and if I decrease sampling frequency, time response i.e. step response is getting worst. I tried various combinations, however no suitable settings with acceptable frequency and time response. I think, I will have to implement opamp based filters instead of digital filter. Any suggestions on this??

0 Likes
JoMe_264151
Expert II

Wouldn't be that enough?

   

Do not forget to increase the ADC conversion rate to 10ksps

   

 

   

Bob

0 Likes
dhgac_296796
New Contributor II

Thanks Bob. I tried these settings, however no improvements found. My signal of interest is very low amplitude and low frequency, so step response is badly affecting temporal features of the signal. Frequency response is excellent but step response not good. If I go for FIR filter, reverse is the case, good time response but frequency response is poor so lot of interference in output signal. How to achieve both is the question..

0 Likes
dhgac_296796
New Contributor II

Is it possible to use multiple filter blocks ? If yes, how may ?? Any example regarding this?? 

0 Likes
JeCo_264681
Contributor

RE: "Should I add filter gain?" The error message you get on the screenshot you submitted is simply that each filter stage offers unity gain. So with two stages you get twice the gain and you are up by 6db for the two stages. You do not need to increase the analog input gain. Instead, reduce each filter stage's gain to -3db and they sum up to 0db output or unity gain. You will not be cheated in the end.
Stay with digital filtering. If you set your parameters right, digital filters offer greater precision than analog filters with their component tolerances and temperature dependence.
I offer two questions to consider. Does your analysis have to be done in real time? If not, I could suggest parameter calculations you could do in C code in your MCU, including Chebyshev or stacked moving average filters. The parameters will be expressed as a fraction of bandwidth.
Another question is what biological processes you are measuring. Are you actually measuring pulses of higher frequencies or do you just need to measure heart beat amplitude and rate or similar amplitude bursts? Perhaps you could eliminate the filter and just use a timer to measure the time between certain threshholds above a certain amplitude. Then you could use a potentiometer or a touchsense to adjust the threshold in real time.

0 Likes
JoMe_264151
Expert II

The filter block is hardware within the PsoC. So you can only use one 2-channel filter.

   

 

   

Bob

0 Likes
dhgac_296796
New Contributor II

Thanks for your suggestions and concern !! 

   

<<Does your analysis have to be done in real time?  

   

well.. yes, I am measuring Electrocardiogram in real time. I want to monitor this signal continuously or frequently. I have plans for signal processing as well in future.

   

But right now focusing on clear signal that can be reliable for primary/basic diagnosis. That is the reason I can not compromise on signal in time domain.

   

Further it is small in amplitude and low frequency.

   

I have got good results with discrete component circuit and now trying for single chip solution.

   

I must say PSoC digital filter responses are actually replicated in filtered signal. Thus you can rely on it as long as you get expected response with component settings.

   

However as I mentioned earlier I want time as well as frequency response at  acceptable level. I basically need 3 filters. LPF for 150 Hz, HPF at 0.05 Hz and Notch at 50 Hz. So I used, compound filter as given earlier. I am not able to find suitable solution. 

   

I think if I can have one digital filter in MCU and rest in DFB .. may be can solve it. Since I get good frequency and time response for Notch and LPF combo. Will it be sensible option?? Am I missing out anything? Pl. suggest..

0 Likes
JeCo_264681
Contributor

Are you being too strict in your filter requirements? "HPF at 0.05Hz" or I think you said earlier 0.5Hz. Either way, most transducers can't output a signal frequency that low. I'm just asking.
As for the notch filter, I referred to "The Scientist and Engineer's Guide to Digital Signal Processing" by Steven W. Smith. In Chapter 19 he states that the narrowest notch bandwidth (0.707 amplitude) that can be obtained with single precision is 0.00003 of the sample frequency. Pushed beyond this limit, attenuation degrades.

0 Likes
JeCo_264681
Contributor

Re: "I think if I can have one digital filter in MCU and rest in DFB .. may be can solve it." If you put your third filter in the MCU your main{} program is going to have to process this while real time data is coming in. Your DFB will continue to accept data until its Transaction Discriptors buffers are full. You can have multiple TDs but as Bob said, each is limited to 4095 bytes -- preferably a multiple of 16 spoke width. When the TDs are full, you would have to handle the interrupt and process your third filter in the MCU and send to your output device. Meanwhile you would be losing real time data until you restarted your filters in the DFB. If I'm wrong, someone please correct me.

0 Likes
dhgac_296796
New Contributor II

That is really informative. I understand that using one filter in MCU will complicate the system. To keep it simple, I have moved to revise my analog front end. My choice of ADC was wrong. Delta sigma ADC with PGAs are doing better job. Also I am getting better signal with FIR filter, 2 stage as discussed earlier. Though analysis is still pending, I see better result with these settings.  I think for filtering, overall system design needs attention, which I was missing. Bob and 78RPM,  Thanks for all the inputs and patience. 

0 Likes
JeCo_264681
Contributor

Just another thought. Instead of filtering 60 Hz hum in th PSoC, use a better power supply or filter or shield the power supply. This goes with your comment about overall design.

0 Likes
dhgac_296796
New Contributor II

Thanks. I should consider this. 

   

Well I want to observe the data in serial plotter. How to configure UART for 16 bit data transmission? Any idea? 

0 Likes
EvPa_264126
Valued Contributor II

I was trying to make an ECG visualization. This is a very old project,   it's here.
Nested project has not been tested - errors are possible.
Perhaps it is useful to you.

0 Likes
dhgac_296796
New Contributor II

Thanks for your inputs.

   

What I am trying to do is basically, transmitting signal over Bluetooth serial module through UART. Refer the case created for experimentation. I am watching signal on Bluetooth terminal installed in mobile.

   

For 16 bit data is it essential to use DMA after Filter?? using Filter_1_Read16() not showing results.

0 Likes
JoMe_264151
Expert II

Filter_1_Read16() not showing results. This can be due to conflict with DMA. I would suggest you to either use polling or DMA.

   

IsInterruptChannelA() API does not promise the returned value to be == 1, datasheet says returned value is positive.

   

So I suggest you to use

   

      while (!Filter_1_IsInterruptChannelA() ) Wait();                    //***

   

 

   

Bob

0 Likes
dhgac_296796
New Contributor II

I modified the code as suggested 

   

 while (!Filter_1_IsInterruptChannelA()== 0 ) Wait(); 

   

 

   

But no change. It gives constant output and no signal values..

   

It works with 8 bit ADC. But output is not uniform ... something like, attached pic.. after 350 samples there is distortion and signal is back after 500 samples

0 Likes
JoMe_264151
Expert II

while (!Filter_1_IsInterruptChannelA()== 0 ) Wait();  // That's not quite right

   

while (!Filter_1_IsInterruptChannelA()) Wait();  // This would be correct

   

while (Filter_1_IsInterruptChannelA()== 0 ) Wait(); // Or this

   

 

   

Bob

0 Likes
dhgac_296796
New Contributor II

Sorry. I tried that one but no output was coming so modified like that. It at least showed output same as with 

   

while (Filter_1_IsInterruptChannelA()== 1 ) Wait(); 

   

I just took a chance. Anyways its not working.

   

while (Filter_1_IsInterruptChannelA()== 1 ) Wait();  is working for 8 bit data but not for 16 bit.

   

May be I will have to go with DMA ..

0 Likes
dhgac_296796
New Contributor II

Is this the problem?? refer image of filter datasheet

   

Filter_SetCoherency(uint8 channel, unit8 byte_select)

   

0 Likes