Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Time Expansion | Problem 2228 | Cody Challenge

How can you slow down any discrete-time signal?

Example

Input original signal x. x = [1 2 3 -1 -2 -5 -4]
We want to slow down n=3 times original signal.
Output signal must be like y. y = [1 0 0 2 0 0 3 0 0 -1 0 0 -2 0 0 -5 0 0 -4]

You can check the question here also:

Click Here

MATLAB Code:

clc
clear all
close all
x=input('Enter the signal'); 
k=input('Enter the required amount of expansion');
Y=[];
j=k-1;
for i=1:length(x)
    Y=[Y x(i)];
    if(i~=length(x))
    for m=1:j
        Y=[Y 0];
    end
    end
end

Explanation:


    
Output:


JAVA CODE:
import java.util.Scanner;
class Wqp
{
public static void main(String args[])
{
Scanner obj=new Scanner(System.in);
System.out.println("Enter the length of the array:");
int l=obj.nextInt();
int a[]=new int[l];
for(int i=0;i<l;i++)
{
System.out.println("Enter the number in array");
a[i]=obj.nextInt();
}
System.out.println("Enter the required amount of expansion");
int p=obj.nextInt();
p=p-1;
for(int i=0;i<l;i++)
{
System.out.print(a[i]+" ");
if(i!=a.length-1)
{
for(int puk=0;puk<p;puk++)
{
System.out.print("0" +" ");
}
}
}
}
}

OUTPUT:



No comments

Popular Posts

Followers