Digital Signal Processing Experiment Based on Matlab: Time Delay

On the first day of the semester, I conducted a Matlab experiment on DSP, focusing on discrete plotting, and I started encountering errors with the stem function again. Although I can use plot to visualize discrete sequences, stem is more appropriate. Below is a comparison of the effects of plotting the same discrete sequence:Digital Signal Processing Experiment Based on Matlab: Time DelayDigital Signal Processing Experiment Based on Matlab: Time DelayHowever, when dealing with time delays, using code generated by AI often results in dimension mismatches with the stem function because it constructs the impulse sequence using zero-padding and then convolves. This method is quite simple, but AI usually fails to calculate how many zeros to pad correctly, gets the row and column vectors mixed up, and forgets to adjust for the index decrement. I typically manually convolve and adjust parameters to ensure dimension matching. Today, I discovered two simpler methods to ensure dimension matching during the experiment.Method 1 involves using an indicator function to directly construct the impulse sequence. In the index vector n, positions equal to k are set to 1, while all other positions are set to 0. This avoids manual counting and concatenation, preventing length mismatches and errors like inconsistent “row/column” implementations. When k is outside the display window, the result is naturally all zeros, which is consistent with the definition, but it can only replace the delta function.Method 2 implements a linear time delay of 1 sample, padding with 0 at the front and discarding one item at the end.Method 1 directly creates the delta function, while Method 2 shifts any sequence to the right by padding with zeros, which is the manual version of Method 1. All three methods are equivalent under the premise of “correct counting, same window, linear shifting”.Method 2 has an interesting point: vector shifting can be done using linear and circular shifts, where the tail samples wrap around to the beginning of the sequence. The latter theoretically alters the frequency domain characteristics. Class is over, and I will head to the cafeteria for some stir-fried beef. Next time, I will write more, but for now, here are some simulation results from Matlab for a random sequence:

Circular shift: |Y/X| maximum deviation from 1 = 4.66e-15

Circular shift: phase slope estimate group delay ≈ 9.000 (target n0=9)

Linear shift: |Y/X| maximum deviation from 1 = 8.23

Digital Signal Processing Experiment Based on Matlab: Time DelayDigital Signal Processing Experiment Based on Matlab: Time Delay

Leave a Comment