Clear Filters
Clear Filters

How to filter real time data I received from Arduino?

3 views (last 30 days)
I am using Arduino Mini to receive real time data. I was able to receive real time data (got help from MATLAB answers) but after I filtered the data the plotting stopped. How can I correct this (I also want the sampling rate of my input signal to be 5000 samples per second):
a = arduino;
% I also want the BaudRate of my signal to be 5000. How do I do that.
writeDigitalPin(a, 'D10', 1);
%% Receiving signal from Arduino and plotting the live data:
figure
al = animatedline;
ax1 = gca;
ax1.YGrid = 'on';
ax1.YLim = [-5 5];
stop = false;
startTime = datetime('now');
while ~stop
% Read current voltage value
v = readVoltage(a,'A0');
% Get current time
t = datetime('now') - startTime;
% Add points to animation
addpoints(al,datenum(t),v)
% Update axes
ax1.XLim = datenum([t-seconds(10) t]);
datetick('x','keeplimits')
drawnow
% Check stop condition
stop = readDigitalPin(a,'D12');
end
%receiving the coordinates from the signal.
[timeLogs,raw_Voltage_Logs] = getpoints(al);
timeSecs = (timeLogs-timeLogs(1))*24*3600;
%% Filtering the raw voltage logs.
%signal_bandpassed = bandpass(raw_Voltage_Logs,[10 500],5000);
transformed_signal = fft(raw_Voltage_Logs);
signal_down_sampled = downsample(transformed_signal,1000);
inverse_transformed = ifft(signal_down_sampled);
signal_highpassed = highpass(inverse_transformed,20,1000);
signal_lowpassed = lowpass(signal_highpassed,300,1000);
final_signal = rms(signal_lowpassed);
%% Plots
figure
ax1 = subplot(2,1,1);
plot(ax1,timeSecs,raw_Voltage_Logs)
title(ax1,'Raw Signal')
ylabel(ax1, 'Voltage(micro-V)')
ax2 = subplot(2,1,2);
plot(ax2,timeSecs,signal_lowpassed)
title(ax2,'Filtered Signal')
ylabel(ax2, 'Voltage(micro-V)')
xlabel('Elapsed time (sec)')

Answers (0)

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!