How can I plot an impulse (sech(x)) consisting of 2002 points, where last 1001 point are zeros?
    8 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Anna_P
 el 24 de Jun. de 2025
  
    
    
    
    
    Comentada: Mathieu NOE
      
 el 26 de Jun. de 2025
            So, I've got 2 sech(x) impulses, 1-st consisting of 1001 points, and 2-nd, consisting of 2002 points. For the 2-nd one I need to set last (right) 1001 points as zeros. How can I do that?
Thank you!
0 comentarios
Respuesta aceptada
  Mathieu NOE
      
 el 24 de Jun. de 2025
        hello 
if you have a recent release (Since R2023b) you can use paddata : here we pad the four first non zero values (your first sech array) with here 2 zeroes 
A = [1; 3; 5; 7];
B = paddata(A,6)
6 comentarios
Más respuestas (2)
  Sam Chak
      
      
 el 24 de Jun. de 2025
        Hi @Anna
Mathieu has shown you how to do that in MATLAB. This is the standard approach in MATLAB computing. However, if you are looking for a math function to include in your thesis or journal paper, you might consider solving the following puzzle: 
What input to the hyperbolic secant function will yield  when
 when  and output zero otherwise?
 and output zero otherwise?
 when
 when  and output zero otherwise?
 and output zero otherwise?ub  = 10;                       % upper bound
x   = linspace(-ub, ub, 2001);  % domain
figure(1)
plot(x, sech(x)), grid on
xlabel('x'), ylabel('sech(x)')
title('Standard Hyperbolic Secant function')
ylim([-0.2, 1.2])
From the plot, since we know that  converges to zero at
 converges to zero at  , or
, or  for
 for  , we can design an intermediate function
, we can design an intermediate function  for the input to the hyperbolic secant such that
 for the input to the hyperbolic secant such that  produces the desired output values within the domain. One approach is to use the signum function to create a step at
 produces the desired output values within the domain. One approach is to use the signum function to create a step at  such that
 such that  for
 for  .
.
 converges to zero at
 converges to zero at  , or
, or  for
 for  , we can design an intermediate function
, we can design an intermediate function  for the input to the hyperbolic secant such that
 for the input to the hyperbolic secant such that  produces the desired output values within the domain. One approach is to use the signum function to create a step at
 produces the desired output values within the domain. One approach is to use the signum function to create a step at  such that
 such that  for
 for  .
.
f   = x + ub/2*sign(x) + ub/2;
y   = sech(f);
figure(2)
subplot(211)
plot(x, f), grid on
xlabel('x'), ylabel('f(x)')
title('Intermediate function, f(x)')
subplot(212)
plot(x, y), grid on
xlabel('x'), ylabel('y')
title('Desired Output')
ylim([-0.2, 1.2])
4 comentarios
  Sam Chak
      
      
 el 25 de Jun. de 2025
        Hi @Anna_P
@Mathieu NOE indeed has a point. My proposed approach does not give an absolute zero. If you require absolute zero for  , then you should consider using this alternative approach, which also reflects my mathematical interpretation of the MATLAB indexing trick:
, then you should consider using this alternative approach, which also reflects my mathematical interpretation of the MATLAB indexing trick:
 , then you should consider using this alternative approach, which also reflects my mathematical interpretation of the MATLAB indexing trick:
, then you should consider using this alternative approach, which also reflects my mathematical interpretation of the MATLAB indexing trick:
Note: You can imagine that  acts like a lowpass filter but allows all
 acts like a lowpass filter but allows all  signals pass for
 signals pass for  . For your info, "Lowpass" is an engineering term, typically used in E&E Engineering and Audio Engineering.
. For your info, "Lowpass" is an engineering term, typically used in E&E Engineering and Audio Engineering.
 acts like a lowpass filter but allows all
 acts like a lowpass filter but allows all  signals pass for
 signals pass for  . For your info, "Lowpass" is an engineering term, typically used in E&E Engineering and Audio Engineering.
. For your info, "Lowpass" is an engineering term, typically used in E&E Engineering and Audio Engineering.ub  = 10;                       % upper bound
x   = linspace(-ub, ub, 2001);  % domain
f1  = 1 - heaviside(x);         % function 1: Unit Step down
f2  = sech(x);                  % function 2: Hyperbolic Secant
y   = f1.*f2;
subplot(211)
plot(x, f1), grid on
xlabel('x')
title('Unit Step down function (Heaviside)')
ylim([-0.2, 1.2])
subplot(212)
plot(x, y), grid on
xlabel('x')
title('Semi-Hyperbolic Secant function')
ylim([-0.2, 1.2])
Ver también
Categorías
				Más información sobre Startup and Shutdown en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









