Khac-Hai / OOP-Nhom-17

0 stars 0 forks source link

cau2 1 #6

Open nvmthu opened 2 months ago

nvmthu commented 2 months ago

public class DiscreteSignal { private int length; private double[] signal;

public DiscreteSignal(int length) { this.length = length; this.signal = new double[length]; }

public void generateSignal(int n) { for (int i = 0; i < length; i++) { if (i == n) { signal[i] = 1.0; // d(n) = 1 tại vị trí n } else { signal[i] = 0.0; // d(n) = 0 tại các vị trí khác } } }

public void displaySignal() { for (int i = 0; i < length; i++) { System.out.println("x(" + i + ") = " + signal[i]); } }

public double getValueAt(int index) { if (index >= 0 && index < length) { return signal[index]; } return 0; } }

Khac-Hai commented 2 months ago

ko ổn

Khac-Hai commented 2 months ago

public class DiscreteSignal implements Signal {

@Override
public void processSignal() {
    // Implementation of discrete signal processing
    System.out.println("Processing discrete signal.");
}

// Additional methods and attributes specific to DiscreteSignal
public double calculateDiscreteValue(int n, int k) {
    if (n == k) {
        return 1.0; // δ(n - k) = 1 when n = k
    } else {
        return 0.0; // δ(n - k) = 0 otherwise
    }
}

} dùng code này

nvmthu commented 2 months ago

ok