Periodically repeating exponential function

Hi! I am trying to design a trapezoidal filter in Matlab by generating a periodically decaying exponential signal that we get from the pre-amplifier. Can someone help me with the code to generate this type of periodic signal?

 Accepted Answer

Try to make just one, then use repmat():
You mean like this:
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Create the X coordinates from 0 to 20 every 0.5 units.
X = 0 : 0.5 : 20;
% Define function that the X values obey.
a = 10 % Arbitrary sample values I picked.
b = 0.4
Y = a + exp(-X * b); % Get a vector. No noise in this Y yet.
% Add noise to Y.
% Y = Y + 0.05 * randn(1, length(Y));
% Now we have noisy training data that we can send to fitnlm().
% Plot the initial data.
subplot(2, 1, 1);
plot(X, Y, 'b-', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
title('This is a single exponential', 'FontSize', fontSize);
% Replicate this 6 times
numReplicates = 6;
Y5 = repmat(Y, [1, numReplicates]);
% Plot the replicated data.
subplot(2, 1, 2);
plot(Y5, 'b-', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
caption = sprintf('This is it replicated %d times', numReplicates);
title(caption, 'FontSize', fontSize);

1 Comment

Yes,this is exactly what I was looking for. Thank you so much!!

Sign in to comment.

More Answers (1)

try using mod() rather than repmat for greater flexibility:
%setup:
Twave=50;
T=100;
Fs = 1;
dt = 1/Fs;
Time = (-T:dt:T-dt)';
tau=20;
%generate periodic exponential "v", scaled 0-1:
v = 1/(1-exp(-Twave/tau))*(1*exp(-mod(Time,Twave)/tau) - exp(-Twave/tau));
figure(1);
clf(1);
plot(Time,v);

Community Treasure Hunt

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

Start Hunting!