Hi!
I'm trying to use the analog discovery to generate a one-period log sine (frequency between 0.1Hz and 100kHz) and record both analog input channels at the same time. I have build a small Matlab script based on the "GSAcquiringAndGenerateData.mlx" example. I need to run on a much higher sampling rate than used in the example. I'd like to use 10MS/s.
Input channels ai0 and ai1 are connected to the output channel ao0 using bnc cables (and the bnc breakout board). Additionally the signal is connected to my scope to see the output of ao0.
At 10MS/s the output looks like in the picture attached (sine_500Hz_at_10MS).
The matlab plot shows the desired output signal (one persiod sine with 500Hz) and the recorded data of ai0 and ai1 (500Hz_sine_10MS_matlab).
When I reduce the sample rate to "only" 1MS/s the signal generated looks like it should (sine_500Hz_at_1MS), but the recorded data of ai0 and ai1 are time-shifted (500Hz_sine_1MS_matlab)
If I lower the frequency of the signal to be generated I usually get a lot of "Samples lost" and "Samples corrupted" warnings in Matlab. As I want to generate one period with a constant sampling rate, the total amount of samples are higher with a lower frequency generated.
E.g. at 10MS/s and a sine with 50Hz a total of 200000 samples are needed. With 500Hz and 10MS/s 20000 samples are needed.
If I run the script with 1MS/s and a sine frequency of 5kHz, the generated signal on the scope looks fine, but the recorded data for ai0 and ai1 look like this:
I also observed that when running the script with the "working" configuration (500Hz and 1MS/s) multiple times, most of the plots look ok, but sometimes the signals are completely off and I get these "Samples lost" and "Samples corrupted" warnings, so feels not very stable. It feels like the problem is somehow connected to the sampling rate and sample-count. When playing around with the sample-rate I sometimes get the error "Channels are set to run at incompatible rates: 1.2e+06, 1.20482e+06". Is there some restriction regarding the sample rate and or the sample-count ? Is there a more in depth example regarding the simultaious generation and aquisition of signals using "high" sample rate (> 10MS/S) ?
I'm running Matlab 2023 on a more or less beefy PC using Windows10. I have WaveForms v3.21.3 installed and I am using the Matlab-Addon aviable here (https://github.com/Digilent/matlab). I have installed the Matlab Support like outlined here: https://digilent.com/reference/test-and-measurement/guides/matlab-getting-started. The legacy support package was not installed before. The AD2 board is connected to my PC using a powered USB3 Hub. I'm also using a 1m, high quality USB2.0 cable with ferrites attached. But using other USB-ports shows the same problem. Until not I have not used an external 5V powery supply for the AD2 (and I don't think this is related to power problems).
It would be really great if someone could give me some hint on what's goning wrong here.
Some background information about what I need to do here:
I have an analog frontend for a special kind of electro-impedace-spectroscopy system. I need to control the frontend using a SPI bus (setting gain etc.) and some digital IO's. I also need to generate an sine as exaction signal with frequencies ranging from 0.1Hz to 100kHz. The analog onput channels are recording the system's answer. From here I'd like to use Matlab to do the rest of the data processing.
This is part of scientific research development and I'm doing the analog hardware development and digital signal processing of a proove-of-concept system. That's why we decided to use Matlab instead of Python because it's easier and more convienent for us to do the development of the dsp stuff in Matlab.
Question
c.brauer
Hi!
I'm trying to use the analog discovery to generate a one-period log sine (frequency between 0.1Hz and 100kHz) and record both analog input channels at the same time. I have build a small Matlab script based on the "GSAcquiringAndGenerateData.mlx" example. I need to run on a much higher sampling rate than used in the example. I'd like to use 10MS/s.
Here is my script:
daqreset; dq = daq("digilent"); addoutput(dq, "AD2_0", "ao0", "Voltage"); addinput(dq, "AD2_0", "ai0", "Voltage"); addinput(dq, "AD2_0", "ai1", "Voltage"); rate = 10e6; dq.Rate = rate; f = 500; n = (rate/f); t = (1:n)/rate; output = sin(2*pi*f*t)'; data = readwrite(dq, output); subplot(3,1,1); plot(output); title('output'); subplot(3,1,2); plot(data.AD2_0_ai0); title('ai0'); subplot(3,1,3); plot(data.AD2_0_ai1); title('ai1');
Input channels ai0 and ai1 are connected to the output channel ao0 using bnc cables (and the bnc breakout board). Additionally the signal is connected to my scope to see the output of ao0.
At 10MS/s the output looks like in the picture attached (sine_500Hz_at_10MS).
The matlab plot shows the desired output signal (one persiod sine with 500Hz) and the recorded data of ai0 and ai1 (500Hz_sine_10MS_matlab).
When I reduce the sample rate to "only" 1MS/s the signal generated looks like it should (sine_500Hz_at_1MS), but the recorded data of ai0 and ai1 are time-shifted (500Hz_sine_1MS_matlab)
If I lower the frequency of the signal to be generated I usually get a lot of "Samples lost" and "Samples corrupted" warnings in Matlab. As I want to generate one period with a constant sampling rate, the total amount of samples are higher with a lower frequency generated.
E.g. at 10MS/s and a sine with 50Hz a total of 200000 samples are needed. With 500Hz and 10MS/s 20000 samples are needed.
If I run the script with 1MS/s and a sine frequency of 5kHz, the generated signal on the scope looks fine, but the recorded data for ai0 and ai1 look like this:
I also observed that when running the script with the "working" configuration (500Hz and 1MS/s) multiple times, most of the plots look ok, but sometimes the signals are completely off and I get these "Samples lost" and "Samples corrupted" warnings, so feels not very stable. It feels like the problem is somehow connected to the sampling rate and sample-count. When playing around with the sample-rate I sometimes get the error "Channels are set to run at incompatible rates: 1.2e+06, 1.20482e+06". Is there some restriction regarding the sample rate and or the sample-count ? Is there a more in depth example regarding the simultaious generation and aquisition of signals using "high" sample rate (> 10MS/S) ?
I'm running Matlab 2023 on a more or less beefy PC using Windows10. I have WaveForms v3.21.3 installed and I am using the Matlab-Addon aviable here (https://github.com/Digilent/matlab). I have installed the Matlab Support like outlined here: https://digilent.com/reference/test-and-measurement/guides/matlab-getting-started. The legacy support package was not installed before. The AD2 board is connected to my PC using a powered USB3 Hub. I'm also using a 1m, high quality USB2.0 cable with ferrites attached. But using other USB-ports shows the same problem. Until not I have not used an external 5V powery supply for the AD2 (and I don't think this is related to power problems).
It would be really great if someone could give me some hint on what's goning wrong here.
Some background information about what I need to do here:
I have an analog frontend for a special kind of electro-impedace-spectroscopy system. I need to control the frontend using a SPI bus (setting gain etc.) and some digital IO's. I also need to generate an sine as exaction signal with frequencies ranging from 0.1Hz to 100kHz. The analog onput channels are recording the system's answer. From here I'd like to use Matlab to do the rest of the data processing.
This is part of scientific research development and I'm doing the analog hardware development and digital signal processing of a proove-of-concept system. That's why we decided to use Matlab instead of Python because it's easier and more convienent for us to do the development of the dsp stuff in Matlab.
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now