SHARE
TWEET

Untitled

Kosinka Dec 16th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.FileOutputStream;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. import static java.lang.Math.sin;
  7.  
  8. public class Main {
  9.  
  10.     public static int td = 0;
  11.     public static int Fd = 0;
  12.     public static int A0 = 0;
  13.     public static int A1 = 0;
  14.     public static int f1 = 0;
  15.     public static ArrayList<Double> source;
  16.     public static ArrayList<Double> filter;
  17.     public static double[] m = {0,0,0,0};
  18.  
  19.     public static void main(String[] args) throws IOException {
  20.         Scanner imp=new Scanner(System. in);
  21.         System.out.println("Введите частоту дискретизации: ");
  22.         Fd=imp.nextInt();
  23.  
  24.         System.out.println("Введите время сигнала: ");
  25.         td=imp.nextInt();
  26.  
  27.         System.out.println("Введите амплитуду А0: ");
  28.         A0=imp.nextInt();
  29.  
  30.         System.out.println("Введите амплитуду А1: ");
  31.         A1=imp.nextInt();
  32.  
  33.         System.out.println("Введите частоту сигнала: ");
  34.         f1=imp.nextInt();
  35.  
  36.         Signal();
  37.         Filter();
  38.         SaveInFile();
  39.     }
  40.  
  41.     public static void Signal(){
  42.         double dt = (1.0/(Fd));
  43.         source = new ArrayList<Double>();
  44.         for(float t =0; t<=td; t+=dt){
  45.             source.add((A0 + A1 * sin(2 * 3.14 * f1 * t)));
  46.         }
  47.  
  48.     }
  49.  
  50.     public static ArrayList<Double> Filter(){
  51.         m[0] = 0;
  52.         m[1] = 0;
  53.         m[2] = 0;
  54.         m[3] = 0;
  55.         filter = new ArrayList<Double>();
  56.         for(int i = 0; i<source.size();i++){
  57.             m[0] = source.get(i);
  58.             double result = result(i);
  59.             filter.add(result);
  60.             m[3] = m[2];
  61.             m[2] = m[1];
  62.             m[1] = m[0];
  63.         }
  64.  
  65.         return filter;
  66.     }
  67.  
  68.     public static double result(int p){
  69.         double result = 0;
  70.         try {
  71.             if(p<0 || p == 1) {
  72.                 return 1;
  73.             }else {
  74.                 result = m[0]+m[1]+2*m[2];
  75.             }
  76.         }
  77.         catch (Exception e){
  78.             System.out.println(e.getMessage());
  79.         }
  80.         return result;
  81.     }
  82.  
  83.     public static void SaveInFile() throws IOException {
  84.         FileOutputStream fos = new FileOutputStream("output.csv");
  85.         String out1 = "#; Source; Filter \n";
  86.         fos.write(out1.getBytes());
  87.         for(int i = 0;i<Main.source.size();i++){
  88.             int count = i + 1;
  89.             String out = count + ";" + Main.source.get(i) + ";" + Main.filter.get(i) + "\n";
  90.             out = out.replace('.',',');
  91.             fos.write(out.getBytes());
  92.         }
  93.         fos.close();
  94.     }
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top